Skip to content

Potential fix for code scanning alert no. 3: Reflected server-side cross-site scripting#978

Draft
gmorador-tribu wants to merge 2 commits intomainfrom
alert-autofix-3
Draft

Potential fix for code scanning alert no. 3: Reflected server-side cross-site scripting#978
gmorador-tribu wants to merge 2 commits intomainfrom
alert-autofix-3

Conversation

@gmorador-tribu
Copy link
Copy Markdown

Potential fix for https://github.com/hypothesis/bouncer/security/code-scanning/3

To fix this without changing behavior, normalize/encode group before inserting it into fragment, the same way q is handled. The best minimal fix is to percent-encode group using urllib.parse.quote(..., safe="") when reading it from request.params. This preserves intended semantics (group still passed in fragment) while preventing injection payloads from being reflected as active markup/script.

In bouncer/views.py, inside goto_url:

  • Change the group assignment (currently raw request.params.get("group", "")) to a quoted value.
  • Keep existing logic unchanged otherwise.

No new imports are required because parse is already imported from urllib.

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

…oss-site scripting

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses code scanning alert #3 (reflected server-side XSS) by ensuring the group query parameter is percent-encoded before being embedded into the client URL fragment generated by goto_url.

Changes:

  • Percent-encode the group request parameter using urllib.parse.quote(..., safe="") before inserting it into the URL fragment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


group = request.params.get("group", "")
group = parse.quote(request.params.get("group", ""), safe="")
query = parse.quote(request.params.get("q", ""))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@copilot also add the unit test for edge cases

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Added three edge case tests in commit c3f146a:

  • test_it_percent_encodes_group_with_special_characters: verifies a <script>alert("xss")</script> payload is fully encoded and raw < never appears in the output URLs
  • test_it_percent_encodes_group_with_angle_brackets_and_quotes: verifies <"group">%3C%22group%22%3E
  • test_it_percent_encodes_group_with_ampersand_and_equals: verifies group&id=1group%26id%3D1

Copy link
Copy Markdown

Copilot AI commented Apr 10, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/python3 python3 -m pytest tests/unit/bouncer/views_test.py -x -q (dns block)
  • www.example.com
    • Triggering command: /usr/bin/python3 python3 -m pytest tests/unit/bouncer/views_test.py -x -q (dns block)
  • www.youtube.com
    • Triggering command: /usr/bin/python3 python3 -m pytest tests/unit/bouncer/views_test.py -x -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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.

3 participants