Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate req.url in renderer #46923

Merged
Merged
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions packages/next/src/server/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,18 @@ async function renderToString(element: React.ReactElement) {
})
}

function validateURL(url: string | undefined): string {
if (!url) {
throw new Error('Invalid request URL')
}
try {
new URL(url, 'http://n')
return url
} catch {
throw new Error('Invalid request URL')
}
}

export async function renderToHTMLOrFlight(
req: IncomingMessage,
res: ServerResponse,
Expand Down Expand Up @@ -1750,8 +1762,7 @@ export async function renderToHTMLOrFlight(
Uint8Array
> = new TransformStream()

// TODO-APP: validate req.url as it gets passed to render.
const initialCanonicalUrl = req.url!
const initialCanonicalUrl = validateURL(req.url)

// Get the nonce from the incoming request if it has one.
const csp = req.headers['content-security-policy']
Expand Down