Skip to content

Commit 1f3b688

Browse files
pukomukomikesamuel
authored andcommitted
allow hyphens in font family name (OWASP#90)
* allow hyphens in font family name * test for — font name
1 parent 95f89f0 commit 1f3b688

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/main/java/org/owasp/html/StylingPolicy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void quotedString(String token) {
155155
if ((meaning & (meaning - 1)) == 0) { // meaning is unambiguous
156156
if (meaning == CssSchema.BIT_UNRESERVED_WORD
157157
&& token.length() > 2
158-
&& isAlphanumericOrSpace(token, 1, token.length() - 1)) {
158+
&& isAlphanumericOrSpaceOrHyphen(token, 1, token.length() - 1)) {
159159
emitToken(Strings.toLowerCase(token));
160160
} else if (meaning == CssSchema.BIT_URL) {
161161
// convert to a URL token and hand-off to the appropriate method
@@ -232,7 +232,7 @@ public void endFunction(String token) {
232232
return sanitizedCss.length() == 0 ? null : sanitizedCss.toString();
233233
}
234234

235-
static boolean isAlphanumericOrSpace(
235+
static boolean isAlphanumericOrSpaceOrHyphen(
236236
String token, int start, int end) {
237237
for (int i = start; i < end; ++i) {
238238
char ch = token.charAt(i);
@@ -243,7 +243,8 @@ static boolean isAlphanumericOrSpace(
243243
} else {
244244
int chLower = ch | 32;
245245
if (!(('0' <= chLower && chLower <= '9')
246-
|| ('a' <= chLower && chLower <= 'z'))) {
246+
|| ('a' <= chLower && chLower <= 'z')
247+
|| ('-' == ch))) {
247248
return false;
248249
}
249250
}

src/test/java/org/owasp/html/StylingPolicyTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public static final void testFontFace() {
129129
assertSanitizedCss(
130130
"font-family:'arial bold' , , , 'helvetica' , sans-serif",
131131
"font-family: 'Arial Bold',,\"\",Helvetica,sans-serif");
132+
assertSanitizedCss(
133+
"font:'chalkboardse-light' , 'helvetica' , monospace",
134+
"FONT: \"ChalkboardSE-Light\", Helvetica, monospace");
132135
}
133136

134137
@Test
@@ -151,6 +154,8 @@ public static final void testFont() {
151154
null, "font: rgb(\"expression(alert(1337))//\")");
152155
assertSanitizedCss("font-size:smaller", "font-size: smaller");
153156
assertSanitizedCss("font:smaller", "font: smaller");
157+
assertSanitizedCss("font:'chalkboardse-light'", "font: 'ChalkboardSE-Light'");
158+
assertSanitizedCss(null, "font: '---");
154159
}
155160

156161
@Test

0 commit comments

Comments
 (0)