File tree Expand file tree Collapse file tree
packages/studio-server/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,8 +45,10 @@ describe("isStudioFontFaceCss", () => {
4545 expect ( isStudioFontFaceCss ( '@font-face { src: url("assets/Brand{1}.ttf"); }' ) ) . toBe ( true ) ;
4646 expect ( isStudioFontFaceCss ( '@font-face { font-family: "x</style><script>"; }' ) ) . toBe ( false ) ;
4747 expect ( isStudioFontFaceCss ( '@font-face { font-family: "x; } body{display:none}' ) ) . toBe ( false ) ;
48- expect ( isStudioFontFaceCss ( '@font-face { font-family: "x\\"; } body{display:none}' ) ) . toBe ( false ) ;
49- expect ( isStudioFontFaceCss ( '@font-face { font-family: "x\\""; } body{display:none}' ) ) . toBe ( false ) ;
48+ expect ( isStudioFontFaceCss ( '@font-face { font-family: "x\\"; } body{}' ) ) . toBe ( false ) ;
49+ expect ( isStudioFontFaceCss ( '@font-face { font-family: "x\\""; } body{}' ) ) . toBe ( false ) ;
50+ expect ( isStudioFontFaceCss ( '@font-face { font-family: "x\r} body{} "; }' ) ) . toBe ( false ) ;
51+ expect ( isStudioFontFaceCss ( "@font-face { font-family: 'x\\\f} body{} '; }" ) ) . toBe ( false ) ;
5052 expect ( isStudioFontFaceCss ( '@font-face { src: url("x") } </style><script>' ) ) . toBe ( false ) ;
5153 expect ( isStudioFontFaceCss ( 42 ) ) . toBe ( false ) ;
5254 } ) ;
Original file line number Diff line number Diff line change 11const FONT_STYLE_RE = / < s t y l e \b [ ^ > ] * d a t a - h f - s t u d i o - f o n t s = ( [ " ' ] ) t r u e \1[ ^ > ] * > ( [ \s \S ] * ?) < \/ s t y l e > / i;
22
3- // Braces only inside quoted strings; `<` nowhere, since `</style` ends the block whatever the quoting.
3+ // Braces only inside quoted strings; `<` nowhere: `</style` ends the block whatever the quoting.
44const ONE_FONT_FACE_RULE =
5- / ^ @ f o n t - f a c e \{ (?: [ ^ { } < " ' \\ ] | " (?: [ ^ " \\ < \n ] | \\ [ ^ < \n ] ) * " | ' (?: [ ^ ' \\ < \n ] | \\ [ ^ < \n ] ) * ' ) * \} $ / ;
5+ / ^ @ f o n t - f a c e \{ (?: [ ^ { } < " ' \\ ] | " (?: [ ^ " \\ < \n \r \f ] | \\ [ ^ < \n \r \f ] ) * " | ' (?: [ ^ ' \\ < \n \r \f ] | \\ [ ^ < \n \r \f ] ) * ' ) * \} $ / ;
66
77export function isStudioFontFaceCss ( css : unknown ) : css is string {
88 return typeof css === "string" && ONE_FONT_FACE_RULE . test ( css ) ;
Original file line number Diff line number Diff line change @@ -666,6 +666,10 @@ describe("registerFileRoutes", () => {
666666 expect ( ( await patch ( { fontFaceCss : `${ css } body{display:none}` } ) ) . status ) . toBe ( 400 ) ;
667667 const quotedBreakout = '@font-face { font-family: "x</style><script>"; }' ;
668668 expect ( ( await patch ( { fontFaceCss : quotedBreakout } ) ) . status ) . toBe ( 400 ) ;
669+ for ( const newline of [ "\r" , "\f" ] ) {
670+ const smuggled = `@font-face { font-family: "x${ newline } } body{background:red} "; }` ;
671+ expect ( ( await patch ( { fontFaceCss : smuggled } ) ) . status ) . toBe ( 400 ) ;
672+ }
669673 expect ( ( await patch ( { fontFaceCss : css } , { id : "missing" } ) ) . status ) . toBe ( 200 ) ;
670674 expect ( readFileSync ( join ( projectDir , "index.html" ) , "utf-8" ) ) . toBe ( original ) ;
671675
You can’t perform that action at this time.
0 commit comments