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/petite-flies-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik-city': patch
---

FIX: return 404 with invalid URL.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ async function runNext(
rebuildRouteInfo: RebuildRouteInfoInternal,
resolve: (value: any) => void
) {
try {
const isValidURL = (url: URL) => new URL(url.pathname + url.search, url);
isValidURL(requestEv.originalUrl);
} catch {
const status = 404;
const message = 'Resource Not Found';
requestEv.status(status);
const html = getErrorHtml(status, message);
requestEv.html(status, html);
return new ServerError(status, message);
}

let rewriteAttempt = 1;

async function _runNext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ export const getImageSizeServer = (
const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
const path: typeof import('path') = await sys.dynamicImport('node:path');

const url = new URL(req.url!, 'http://localhost:3000/');
let url;
try {
url = new URL(req.url!, 'http://localhost:3000/');
} catch {
res.statusCode = 404;
res.end();
return;
}
if (req.method === 'GET' && url.pathname === '/__image_info') {
const imageURL = url.searchParams.get('url');
res.setHeader('content-type', 'application/json');
Expand Down
8 changes: 7 additions & 1 deletion starters/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ Error.stackTraceLimit = 1000;
const cache = new Map<string, Promise<QwikManifest>>();
async function handleApp(req: Request, res: Response, next: NextFunction) {
try {
const url = new URL(req.url, address);
let url;
try {
url = new URL(req.url, address);
} catch {
res.status(404).send();
return;
}
if (existsSync(url.pathname)) {
const relPath = relative(startersAppsDir, url.pathname);
if (!relPath.startsWith(".")) {
Expand Down