Skip to content

Restrict external navigation with goto by default #8775

@efstajas

Description

@efstajas

Describe the problem

Currently, you can pass an absolute external path (e.g. "https://wikipedia.com") to the goto function, and it will happily navigate away to outside the SvelteKit app.

Generally, this makes sense of course, but it caught me off-guard. Having used Nuxt before, where the router.navigateTo function forbids external navigation unless you explicitly set external to true in its options, I implemented a mechanism that allows our sign-in page to push the user back to a route-guarded page using a backTo URL parameter that would get appended to the sign-in page URL. Once the user signed in, the page would check whether backTo is set to a path, and if yes pass its value to goto.

Recently, it was found that it was in fact possible to set this parameter to an absolute external URL, and it would happily push the user to that external page. Consequently, even javascript: URLs were possible, resulting in an XSS vulnerability.

I understand that passing any user-editable string to goto was probably foolish on my part, but I didn't even consider the fact that external navigation would be possible at the time. Luckily, we caught this before going live on production, but I feel like this could be a common pitfall (especially given at least one other popular framework protects against it), with potentially severe consequences.

Describe the proposed solution

Add a new paremeter external to goto's options object, which is set to false by default. If false, the function should ensure that the navigation would not push the user outside the current application, and throw an error if it would. If true, the current behavior should apply.

See Nuxt.js' navigateTo function. https://nuxt.com/docs/api/utils/navigate-to

Alternatives considered

Add the external parameter, but set it to true by default, so developers can opt-in to blocking external URLs when passing user-editable strings to goto while avoiding a breaking change.

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions