Skip to content

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

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

Potential fix for code scanning alert no. 33: Client-side cross-site scripting#30
Dargon789 merged 1 commit intomasterfrom
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 cross-site scripting vulnerability, ensure that only safe, expected values for the redirection target are used, and never directly interpolate unsanitized user input (such as params.next) into URLs or location changes. Since only known path strings are acceptable, we should always use the trusted value from the path array rather than the raw params.next. Specifically, in the line window.location.replace(${params.next}?next=${nextPath}), we should replace params.next with the trusted path[index] value that was matched from the array (or, to be extra safe, use nextPath). This avoids using raw user input and prevents injection vulnerabilities.

Changes should be made in frontend/src/app/shared/common.utils.ts, by editing the implementation of handleDemoRedirect so that only safe, trusted strings from the predefined array are used in the location replacement.

No new methods or external dependencies are required.

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

Summary by Sourcery

Bug Fixes:

  • Change handleDemoRedirect to use the trusted path[index] value in window.location.replace rather than params.next

…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

Replaces direct use of unsanitized params.next in the redirect URL with the trusted value from a predefined path array in handleDemoRedirect, closing the XSS hole by only interpolating known-safe strings.

Sequence diagram for safe redirection in handleDemoRedirect

sequenceDiagram
participant User as actor User
participant Route as ActivatedRoute
participant Router as Router
participant Utils as common.utils.ts
User->>Route: Navigates with next param
Route->>Utils: handleDemoRedirect(route, router)
Utils->>Utils: Validate params.next against path array
alt params.next is valid
Utils->>Utils: Compute nextPath
Utils->>Browser: window.location.replace(`${path[index]}?next=${nextPath}`) after 15s
else params.next is invalid
Utils->>Utils: No redirect
end
Loading

File-Level Changes

Change Details Files
Sanitize redirect target by swapping raw user input for a trusted path value
  • Replaced ${params.next} with ${path[index]} in window.location.replace
  • Retained nextPath selection logic while restricting redirection to known paths
frontend/src/app/shared/common.utils.ts

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 09:17
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 410b52a into master Oct 2, 2025
21 checks passed
@Dargon789 Dargon789 deleted the alert-autofix-33 branch October 2, 2025 09:19
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