Skip to content

Commit

Permalink
tweak xss tests (#6976)
Browse files Browse the repository at this point in the history
* tweak xss tests. closes #2648, i think?

* escape error objects
  • Loading branch information
Rich-Harris authored Oct 31, 2022
1 parent 655e34e commit 87b8313
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export async function render_response({
env: ${s(options.public_env)},
hydrate: ${page_config.ssr ? `{
status: ${status},
error: ${s(error)},
error: ${devalue(error)},
node_ids: [${branch.map(({ node }) => node.index).join(', ')}],
params: ${devalue.uneval(event.params)},
routeId: ${s(event.routeId)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
import { page } from '$app/stores';
</script>

<h1 id="one">{$page.params.slug}</h1>
<h1 id="one">{$page.params.path}</h1>
13 changes: 10 additions & 3 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1729,16 +1729,23 @@ test.describe('XSS', () => {
}
});

const uri_xss_payload = encodeURIComponent('</script><script>window.pwned=1</script>');
const uri_xss_payload = '</script><script>window.pwned=1</script>';
const uri_xss_payload_encoded = encodeURIComponent(uri_xss_payload);

test('no xss via dynamic route path', async ({ page }) => {
await page.goto(`/xss/${uri_xss_payload}`);
await page.goto(`/xss/${uri_xss_payload_encoded}`);

expect(await page.textContent('h1')).toBe(uri_xss_payload);

// @ts-expect-error - check global injected variable
expect(await page.evaluate(() => window.pwned)).toBeUndefined();
});

test('no xss via query param', async ({ page }) => {
await page.goto(`/xss/query?key=${uri_xss_payload}`);
await page.goto(`/xss/query?key=${uri_xss_payload_encoded}`);

expect(await page.textContent('#one')).toBe(JSON.stringify({ key: [uri_xss_payload] }));
expect(await page.textContent('#two')).toBe(JSON.stringify({ key: [uri_xss_payload] }));

// @ts-expect-error - check global injected variable
expect(await page.evaluate(() => window.pwned)).toBeUndefined();
Expand Down

0 comments on commit 87b8313

Please sign in to comment.