Repository navigation
ci(security): model Cacti's escapers by output context in the Semgrep rules - #8982
Open
somethingwithproof wants to merge 2 commits into
Open
somethingwithproof wants to merge 2 commits into
somethingwithproof wants to merge 2 commits into
Conversation
… 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
Bot
force-pushed
the
chore/semgrep-escaper-models
branch
from
November 26, 2026 08:44
cb71924 to
fd925f3
Compare
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #8981
Two commits:
__esc*()to the request-variable rule andhtml_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 treatsdb_fetch_*()results as request text, which the stored-value rules already cover, andget_username()is modelled as a stored-text source.--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. Theruntime-taint.phpself-test also passes, andactionlintreports nothing for the workflow.get_username()prints intree.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.