Skip to content

Commit a2b40db

Browse files
authored
fix(server-renderer): reject CR in attribute names (#15266)
1 parent f897565 commit a2b40db

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/server-renderer/__tests__/ssrRenderAttrs.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ describe('ssr: renderAttrs', () => {
118118
),
119119
).toBe(` viewBox="foo"`)
120120
})
121+
122+
test('ignore attr names containing carriage returns', () => {
123+
expect(
124+
ssrRenderAttrs({
125+
id: 'safe',
126+
['x\rautofocus\ronfocus']: 'alert(1)',
127+
}),
128+
).toBe(` id="safe"`)
129+
expect(`unsafe attribute name`).toHaveBeenWarned()
130+
expect(`Skipped rendering unsafe attribute name`).toHaveBeenWarned()
131+
})
121132
})
122133

123134
describe('ssr: renderAttr', () => {

packages/shared/src/domAttrConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function includeBooleanAttr(value: unknown): boolean {
3333
return !!value || value === ''
3434
}
3535

36-
const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/
36+
const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u000d\u0020]/
3737
const attrValidationCache: Record<string, boolean> = {}
3838

3939
export function isSSRSafeAttrName(name: string): boolean {

0 commit comments

Comments
 (0)