Skip to content

Potential fix for code scanning alert no. 33: Client-side cross-site scripting#39

Merged
Dargon789 merged 1 commit intomainfrom
alert-autofix-33
Oct 2, 2025
Merged

Potential fix for code scanning alert no. 33: Client-side cross-site scripting#39
Dargon789 merged 1 commit intomainfrom
alert-autofix-33

Conversation

@Dargon789
Copy link
Owner

@Dargon789 Dargon789 commented Oct 2, 2025

Potential fix for https://github.com/Dargon789/mempool/security/code-scanning/33

To fix the problem, ensure only permitted paths are ever used in window.location.replace. Rather than interpolating the user-provided params.next in the resulting URL, use the whitelisted version from the path array after validation. Refuse to use any value not in the allowed list. Specifically, in handleDemoRedirect, change the redirect line to use the validated value (params.next must be in path, so use the whitelisted entry directly for redirection) and never trust user input for the base URL. This prevents injection of a malicious value.

Edit file frontend/src/app/shared/common.utils.ts:

  • On line 233, change window.location.replace(`${params.next}?next=${nextPath}`) to use the whitelisted value (window.location.replace(${path[index]}?next=${nextPath}))
  • No new imports are required.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Summary by Sourcery

Bug Fixes:

  • Prevent client-side XSS by using validated whitelisted paths in window.location.replace instead of untrusted user input.

…scripting

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: AU_gdev_19 <64915515+Dargon789@users.noreply.github.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 2, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes a client-side XSS vulnerability in handleDemoRedirect by ensuring the redirection URL uses only a whitelisted path entry instead of the untrusted params.next value.

Sequence diagram for secure redirect in handleDemoRedirect

sequenceDiagram
participant User
participant "handleDemoRedirect()"
participant "window.location.replace()"
User->>"handleDemoRedirect()": Triggers redirect with params.next
"handleDemoRedirect()"->>"handleDemoRedirect()": Validate params.next against whitelist (path[])
alt params.next is in whitelist
    "handleDemoRedirect()"->>"window.location.replace()": Redirect to whitelisted path[index]?next=nextPath
else params.next is not in whitelist
    "handleDemoRedirect()"->>User: No redirect (or error)
end
Loading

File-Level Changes

Change Details Files
Use validated whitelist entry for window.location.replace to prevent XSS
  • Replaced window.location.replace interpolation of params.next with the whitelisted path[index]
  • Kept nextPath logic unchanged
frontend/src/app/shared/common.utils.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Dargon789 Dargon789 marked this pull request as ready for review October 2, 2025 17:47
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Dargon789 Dargon789 merged commit ad92bad into main Oct 2, 2025
20 checks passed
@Dargon789 Dargon789 deleted the alert-autofix-33 branch October 2, 2025 17:49
@Dargon789 Dargon789 restored the alert-autofix-33 branch October 22, 2025 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant