-
Notifications
You must be signed in to change notification settings - Fork 3
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
Nounly Sample #336
base: main
Are you sure you want to change the base?
Nounly Sample #336
Conversation
a.setAttribute("data-etag", r.etag); | ||
a.setAttribute("data-date", r.date); | ||
a.title = r.origUrl || r.url; | ||
a.href = r.url; |
Check warning
Code scanning / CodeQL
Client-side URL redirect Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 1 day ago
To fix the problem, we need to ensure that the URL used for redirection is validated against a list of authorized URLs. This can be done by maintaining a list of allowed URLs and checking if the user-provided URL matches any entry in this list before performing the redirection.
- Create a list of authorized URLs.
- Validate the user-provided URL against this list.
- Only perform the redirection if the URL is authorized.
-
Copy modified lines R2-R9 -
Copy modified lines R95-R99
@@ -1,2 +1,10 @@ | ||
(function () { | ||
const authorizedUrls = [ | ||
"https://example.com", | ||
"https://another-example.com" | ||
]; | ||
|
||
function isAuthorizedUrl(url) { | ||
return authorizedUrls.some(authorizedUrl => url.startsWith(authorizedUrl)); | ||
} | ||
function E(id) { return document.getElementById(id); } | ||
@@ -86,3 +94,7 @@ | ||
a.title = r.origUrl || r.url; | ||
a.href = r.url; | ||
if (isAuthorizedUrl(r.url)) { | ||
a.href = r.url; | ||
} else { | ||
a.href = "#"; | ||
} | ||
a.appendChild(document.createTextNode(r.code)); |
Fixes #124
Nounly is a URL shortener website built with Go, JavaScript, and Redis, and can be deployed with Defang as a sample.
See the real Noun.ly website for reference.
Samples Checklist
✅ All good!