Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/secure-vnode-slot-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik.dev/core': patch
---

fix: encode vnode metadata keys in script output.
2 changes: 1 addition & 1 deletion packages/qwik/src/core/client/vnode-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ function materializeFromVNodeData(
} else if (peek() === VNodeDataChar.SEPARATOR) {
// Custom attribute: |key|value
const keyValue = consumeValue();
const key = decodeVNodeDataString(keyValue);
const key = decodeURIComponent(decodeVNodeDataString(keyValue));
const valueSeparatorIdx = dataIdx + keyValue.length + 1;
const isEscapedValue = getChar(valueSeparatorIdx + 1) === VNodeDataChar.SEPARATOR;
let value;
Expand Down
10 changes: 10 additions & 0 deletions packages/qwik/src/core/client/vnode.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ describe('vnode', () => {
</test>
);
});
it('should decode encoded custom attribute names on Virtual', () => {
const attrName = '</script><script>globalThis.__qwik_xss=1</script>';
const encodedAttrName = encodeVNodeDataString(encodeVNodeDataKey(attrName));
parent.innerHTML = ``;
document.qVNodeData.set(parent, `{|${encodedAttrName}|value}`);

const virtual = vnode_getFirstChild(vParent)!;

expect(vnode_getProp(virtual, attrName, null)).toBe('value');
});
it('should decode encoded slot names on Virtual', () => {
const slotName = '</script>|~;=?@ zażółć';
const encodedSlotName = encodeVNodeDataString(encodeVNodeDataKey(slotName));
Expand Down
26 changes: 26 additions & 0 deletions packages/qwik/src/server/ssr-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,32 @@ describe('SSR Container', () => {
);
});

it('should encode custom attribute names in emitVNodeData', () => {
const { container, writer } = createTestContainer();
container.openContainer();
container.serializationCtx.$roots$.push({});

const customKey = '</script><script>globalThis.__qwik_xss=1</script>';
(container as any).vNodeDatas = [
[
VNodeDataFlag.SERIALIZE | VNodeDataFlag.VIRTUAL_NODE,
{ [customKey]: 'projection-ref' },
OPEN_FRAGMENT,
CLOSE_FRAGMENT,
],
];

(container as any).emitVNodeData();

const output = writer.toString();
const encodedKey = encodeVNodeDataString(encodeVNodeDataKey(customKey));

expect(output).not.toContain(customKey);
expect(output).toContain(
`${VNodeDataChar.SEPARATOR_CHAR}${encodedKey}${VNodeDataChar.SEPARATOR_CHAR}`
);
});

it('should encode slot names in emitVNodeData', () => {
const { container, writer } = createTestContainer();
container.openContainer();
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/server/ssr-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
default: {
encodeValue = encodeURI;
this.write(VNodeDataChar.SEPARATOR_CHAR);
this.write(encodeVNodeDataString(key));
this.write(encodeVNodeDataString(encodeVNodeDataKey(key)));
this.write(VNodeDataChar.SEPARATOR_CHAR);
}
}
Expand Down
Loading