Skip to content

Commit

Permalink
add url validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mscoutermarsh committed Dec 2, 2023
1 parent 5dc8635 commit 972cbdb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,18 @@ async function handleRequest(request) {
let origin = searchParams.get('origin')
let headers = null

if (isValidHttpUrl(url)) {
headers = await getHeaders(url, method, origin)
} else {
url = ''
if (!isValidHttpUrl(url)) {
return new Response("Invalid URL provided", { status: 400, headers: { "content-type": "text/plain" } });
}

if (!isValidHttpUrl(origin)) {
return new Response("Invalid origin provided", { status: 400, headers: { "content-type": "text/plain" } });
}

// Validate HTTP method
const validMethods = ["get", "post", "put", "patch", "head", "options"];
if (!validMethods.includes(method.toLowerCase())) {
return new Response("Invalid HTTP method provided", { status: 400, headers: { "content-type": "text/plain" } });
}

return new Response(html(url, origin, method, headers, request), {
Expand Down

0 comments on commit 972cbdb

Please sign in to comment.