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

JS: Add New XSS sink - Next.js router.push/replace #12787

Merged
merged 4 commits into from
Apr 12, 2023

Conversation

tyage
Copy link
Contributor

@tyage tyage commented Apr 8, 2023

Made Next.js router's push/replace methods as XSS sink.
They should be XSS sink because XSS occurs when their argument is javascript:alert(1).

https://nextjs.org/docs/api-reference/next/router#routerpush
https://nextjs.org/docs/api-reference/next/router#routerreplace

BTW, those methods are considered as XSS sink in the test code of ClientSideUrlRedirect but they are not actually treated as XSS sink.

export function nextRouter() {
const router = useRouter();
return <span onClick={() => router.push(document.location.hash.substr(1))}>Click to XSS 1</span>
}
import { withRouter } from 'next/router'
function Page({ router }) {
return <span onClick={() => router.push(document.location.hash.substr(1))}>Click to XSS 2</span>
}

@tyage tyage requested a review from a team as a code owner April 8, 2023 09:33
@github-actions github-actions bot added the JS label Apr 8, 2023
@tyage tyage changed the title Add New XSS sink: Next.js router.push/replace JS: Add New XSS sink - Next.js router.push/replace Apr 10, 2023
@erik-krogh erik-krogh self-assigned this Apr 12, 2023
Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks 👍

I noticed that HistoryWriteUrlSink could use the same treatment, I'll do that myself in a followup PR.

@erik-krogh erik-krogh merged commit 8cb54b7 into github:main Apr 12, 2023
@tyage tyage deleted the add-router-sink branch April 13, 2023 00:51
@tyage
Copy link
Contributor Author

tyage commented Apr 13, 2023

@erik-krogh
Thanks for merging!

I didn't aware that @npm/history can be a sink because I tested with history v4.
It seems history v4 is safe but history v5 is not safe 😓

history v4
https://stackblitz.com/edit/js-xervrs

history v5
https://stackblitz.com/edit/js-q6v4fa

remix-run/history#811

@erik-krogh
Copy link
Contributor

I didn't aware that @npm/history can be a sink because I tested with history v4. It seems history v4 is safe but history v5 is not safe 😓

Interesting....
I just tested with the latest version to confirm that it was a thing.

I don't think I'll add a version check to the @npm/history sink, as upgrading to the latest version can make you vulnerable.

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

Successfully merging this pull request may close these issues.

2 participants