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

security: Client-side URL redirect #16

Open
aldy505 opened this issue Aug 19, 2021 · 0 comments
Open

security: Client-side URL redirect #16

aldy505 opened this issue Aug 19, 2021 · 0 comments

Comments

@aldy505
Copy link
Member

aldy505 commented Aug 19, 2021

<Link href={`/${contentType}/${slug}`}>

Redirecting to a URL that is constructed from parts of the DOM that may be controlled by an attacker can facilitate phishing attacks. In these attacks, unsuspecting users can be redirected to a malicious site that looks very similar to the real site they intend to visit, but which is controlled by the attacker.

Recommendation

To guard against untrusted URL redirection, it is advisable to avoid putting user input directly into a redirect URL. Instead, maintain a list of authorized redirects on the server; then choose from that list based on the user input provided.

Example

The following example uses a regular expression to extract a query parameter from the document URL, and then uses it to construct a new URL to redirect to without any further validation. This may allow an attacker to craft a link that redirects from a trusted website to some arbitrary website of their choosing, which facilitates phishing attacks:

window.location = /.*redirect=([^&]*).*/.exec(document.location.href)[1];

References
OWASP: XSS Unvalidated Redirects and Forwards Cheat Sheet.
Common Weakness Enumeration: CWE-79.
Common Weakness Enumeration: CWE-116.
Common Weakness Enumeration: CWE-601.


security alert from codeql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant