Skip to content

ci(security): model Cacti's escapers by output context in the Semgrep rules - #8982

Open
somethingwithproof wants to merge 2 commits into
Cacti:developfrom
somethingwithproof:chore/semgrep-escaper-models
Open

somethingwithproof wants to merge 2 commits into
Cacti:developfrom
somethingwithproof:chore/semgrep-escaper-models

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

Fixes #8981

Two commits:

  1. Model Cacti's escapers by the output context they protect. Adds __esc*() to the request-variable rule and html_escape_attr(), htmlerv(), html_escape_request_var() and __esc_xn() to all three XSS rules. html_escape_url() only escapes for the attribute, so it counts as a sanitizer only behind a literal page path such as 'graphs.php?id=' . $id; a whole URL from a request or stored value is still reported. The request-variable rule no longer treats db_fetch_*() results as request text, which the stored-value rules already cover, and get_username() is modelled as a stored-text source.
  2. Run the changed-file scan with --jobs 1. With parallel jobs, two scans of develop with the same rules differed by 41 findings, and a scan of eight large pages found 44 findings where one job finds 53. One job gives the same result every time and took the same 4 to 6 seconds for those eight pages.

Verification, with the pinned Semgrep image:

  • semgrep --test tests/security/semgrep/ passes, with new fixtures that fail on the old rules. The runtime-taint.php self-test also passes, and actionlint reports nothing for the workflow.
  • A single-job scan of every non-vendor PHP file on develop goes from 273 findings to 208. I read each of the 65 removed findings: all are escaped values, numeric ids or markup built from literals. The only findings added are the three get_username() prints in tree.php, fixed in Tree pages print user names without escaping on develop #8980's pull request.

#8448 also edits .github/workflows/semgrep.yml, at the self-test line; this change is in the scan step, so the two do not overlap.

@somethingwithproof
somethingwithproof requested a review from a team as a code owner November 26, 2026 02:56
@somethingwithproof
somethingwithproof removed the request for review from a team November 26, 2026 02:56
@somethingwithproof somethingwithproof added this to the v1.3.0 milestone Nov 26, 2026
@somethingwithproof somethingwithproof added the enhancement General tag for an enhancement label Nov 26, 2026
… rules

The XSS rules missed several of Cacti's own escapers, so escaped output was
reported as unescaped. The request-variable rule did not know __esc(),
__esc_n() or __esc_x(), and no rule knew html_escape_attr(), htmlerv(),
html_escape_request_var() or __esc_xn(). The request-variable rule also
treated a whole fetched row as request text whenever a request variable was
bound as a query parameter, so ids and escaped names of fetched rows were
reported.

Add the missing escapers, and stop treating db_fetch_*() results as request
text; the stored-value rules already decide whether fetched columns are safe.
html_escape_url() only escapes for the attribute, so a value that supplies
the whole URL can still carry a javascript: scheme. It now counts as a
sanitizer only behind a literal page path. get_username() returns the stored
user name and is modelled as a stored-text source, which keeps the flows that
the row change would otherwise have dropped.

With one job, a scan of every non-vendor PHP file on develop goes from 273
findings to 208. It adds no finding apart from three get_username() prints in
tree.php, and each of the 68 removed findings is an escaped value, a numeric
id, or markup built from literals.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
With parallel jobs, the taint results over Cacti's large files changed from
run to run: two scans of develop with the same rules differed by 41
findings, and a scan of eight large pages found 44 findings where one job
finds 53. A single job gives the same result every time and took the same
four to six seconds for those eight files.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@github-actions
github-actions Bot force-pushed the chore/semgrep-escaper-models branch from cb71924 to fd925f3 Compare November 26, 2026 08:44
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement General tag for an enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semgrep XSS rules report escaped output and vary between runs

1 participant