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
4 changes: 2 additions & 2 deletions packages/void/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@
"type": "object",
"description": "URL rewrites. Keys are source URL patterns (path-only `/path` or host-scoped `https://host/path`); values are destination paths. Serves content from the destination without changing the browser URL. Destinations must start with \"/\" and must not contain \"?\" — the incoming request's query string is preserved automatically.",
"patternProperties": {
"^(/|https://)": { "type": "string", "pattern": "^/[^?]*$" }
"^(/|https://)": { "type": "string", "pattern": "^/(?!/)[^?]*$" }
},
"additionalProperties": false
},
"fallbacks": {
"type": "object",
"description": "Fallback rewrites. Same shape as `rewrites`, but only fire when no static asset matched the request. Useful for SPA shells or default-locale catch-alls without pre-empting real routes. Destinations must start with \"/\" and must not contain \"?\".",
"patternProperties": {
"^(/|https://)": { "type": "string", "pattern": "^/[^?]*$" }
"^(/|https://)": { "type": "string", "pattern": "^/(?!/)[^?]*$" }
},
"additionalProperties": false
}
Expand Down
16 changes: 16 additions & 0 deletions packages/void/test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,22 @@ describe('readConfig redirects', () => {
}
});

it('schema.json rewrite/fallback dest pattern rejects protocol-relative "//"', () => {
const schema = JSON.parse(readFileSync(join(import.meta.dirname, '../../schema.json'), 'utf8'));
for (const field of ['rewrites', 'fallbacks']) {
const destPattern = new RegExp(
schema.properties.routing.properties[field].patternProperties['^(/|https://)'].pattern,
);
// Runtime accepts internal paths and rejects protocol-relative dests + query strings.
for (const dest of ['/en/docs', '/', '/index.html']) {
expect(destPattern.test(dest)).toBe(true);
}
for (const dest of ['//evil.com/x', '//', '///x', '/x?a=1', 'en/docs']) {
expect(destPattern.test(dest)).toBe(false);
}
}
});

it('publishes schema.json as a package file and subpath export', () => {
const packageJson = JSON.parse(
readFileSync(join(import.meta.dirname, '../../package.json'), 'utf8'),
Expand Down