Skip to content

FIX: Detect obfuscated SQL injection and javascript: payloads in output scorers - #3640

Merged
Roman Lutz (romanlutz) merged 9 commits into
microsoft:mainfrom
shashank03-dev:fix/sql-xss-scorer-obfuscation
Nov 2, 2026
Merged

Roman Lutz (romanlutz) merged 9 commits into
microsoft:mainfrom
shashank03-dev:fix/sql-xss-scorer-obfuscation

Conversation

@shashank03-dev

@shashank03-dev Dev3 ^~^ (shashank03-dev) commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Related to #3324

The SQL injection and XSS scorers missed some very common payloads, so a response with a working exploit in it was scored as safe.

  • SQLInjectionOutputScorer missed ' OR '1'='1, admin' OR 1=1-- and UNION/**/SELECT. It now flags a quote followed by OR and a value compared to itself, and allows comments between UNION and SELECT. Like the existing comment check, it skips escaped quotes and normal quoted strings, so name = 'bob' OR 1=1 and Pick 'a' OR 'b'. still score False.
  • XSSOutputScorer missed javascript: links written with HTML character codes or with tabs and newlines inside the word, like jav	ascript: or javascript:. Browsers decode these and still run the script. The href/src/action/formaction check now accepts these forms, and still ignores look-alikes that decode to a different character, like &#x6Aavascript:.

Not covered here: OR TRUE, 'a'<>'b', ||, MySQL /*!...*/ comments, and encoded javascript: outside an HTML attribute. Custom patterns behave the same as before.

Tests: Added matching and non-matching cases for each new form. The XSS cases agree with Python's HTML parser, including 100,000 random variations that cover both letter cases and every encoding form, the SQL cases were run against a vulnerable SQLite query to confirm they work as exploits, and the tautology and UNION patterns were fuzzed against SQLite with no false positives. Two existing ' OR '1'='1'-- tests now also report Tautology Bypass.

Detect CR-ended PostgreSQL UNION comments while retaining LF-only SQLite and MySQL handling. Match each convention across the full indicator and cover public scoring, persistence, and mixed-convention negatives.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 07:33
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The XSS scorer produces false positives by accepting Unicode whitespace before encoded schemes and literal tabs or newlines in unquoted attributes, contrary to URL and HTML parsing behavior.

2 open issues
What changed in this PR

This PR expands PyRIT’s SQL injection and XSS output detection to address selected gaps from #3324 while preserving custom-pattern behavior.

Changes:

  • Adds quote-breakout tautology detection and comment-separated UNION SELECT matching.
  • Recognizes entity-encoded and control-character-obfuscated javascript: attribute values.
  • Adds regression tests and updates the SQL scorer examples.
File Description
tests/​unit/​score/​regex/​test_xss_output_scorer.py Adds obfuscation, look-alike, performance, and custom-pattern tests.
tests/​unit/​score/​regex/​test_sql_injection_output_scorer.py Tests tautologies, comment separators, dialect handling, and score persistence.
pyrit/​score/​true_false/​regex/​xss_output_scorer.py Expands JavaScript URI matching for encoded and split schemes.
pyrit/​score/​true_false/​regex/​sql_injection_output_scorer.py Adds tautology matching and comment-aware UNION detection.
doc/​code/​scoring/​1_true_false_scorers.py Adds a tautology payload to the documented SQL examples.
doc/​code/​scoring/​1_true_false_scorers.ipynb Mirrors the SQL example update in the notebook.

Review effort: Balanced

Limit URL padding to removable ASCII controls, reject HTML-replaced NUL, and distinguish literal whitespace in quoted values from references valid in either attribute form. Cover verdicts and persisted scores against HTML parsing.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 2, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 2, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 2, 2026
Merged via the queue into microsoft:main with commit a214848 Nov 2, 2026
66 checks passed
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