]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(server-renderer): reject CR in attribute names (#15266) main
authoredison <edison11051@gmail.com>
Tue, 11 Aug 2026 07:28:17 +0000 (15:28 +0800)
committerGitHub <noreply@github.com>
Tue, 11 Aug 2026 07:28:17 +0000 (15:28 +0800)
packages/server-renderer/__tests__/ssrRenderAttrs.spec.ts
packages/shared/src/domAttrConfig.ts

index 979e3a4b3bdee77e6f379cda8f7ae08fafe906ef..09bf42301cbf2f257e9881effc407bcd16fac17d 100644 (file)
@@ -118,6 +118,17 @@ describe('ssr: renderAttrs', () => {
       ),
     ).toBe(` viewBox="foo"`)
   })
+
+  test('ignore attr names containing carriage returns', () => {
+    expect(
+      ssrRenderAttrs({
+        id: 'safe',
+        ['x\rautofocus\ronfocus']: 'alert(1)',
+      }),
+    ).toBe(` id="safe"`)
+    expect(`unsafe attribute name`).toHaveBeenWarned()
+    expect(`Skipped rendering unsafe attribute name`).toHaveBeenWarned()
+  })
 })
 
 describe('ssr: renderAttr', () => {
index 797cc1126c025c1bd581cbcb753de9afb41efdfe..bac07abe5a3f031909c2f0509a595d95bb395e24 100644 (file)
@@ -33,7 +33,7 @@ export function includeBooleanAttr(value: unknown): boolean {
   return !!value || value === ''
 }
 
-const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/
+const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u000d\u0020]/
 const attrValidationCache: Record<string, boolean> = {}
 
 export function isSSRSafeAttrName(name: string): boolean {