Skip to content

Fix MLAllowlist shadowing (GHSA-cffv-grgg-g429)#278

Open
thomas-chauchefoin-tob wants to merge 2 commits into
masterfrom
fix/ghsa-cffv-grgg-g429-mlallowlist-shadowing
Open

Fix MLAllowlist shadowing (GHSA-cffv-grgg-g429)#278
thomas-chauchefoin-tob wants to merge 2 commits into
masterfrom
fix/ghsa-cffv-grgg-g429-mlallowlist-shadowing

Conversation

@thomas-chauchefoin-tob
Copy link
Copy Markdown
Collaborator

@thomas-chauchefoin-tob thomas-chauchefoin-tob commented May 27, 2026

@reapermunky reported in GHSA-cffv-grgg-g429 that AnalysisContext.shorten_code() would mutate the shared dedup set of the context analysis, which then prevents future analysis passes from yielding an AnalysisResult. Since UnsafeImportsML already marks every import with AnalysisContext.shorten_code(), MLAllowlist would never analyze them. The first commit moves dedup tracking from AnalysisContext.shorten_code() to a separate function AnalysisContext.mark_reported().

Now that MLAllowlist is no longer dead code, it conflicts with other analysis passes (for instance, combining results from MLAllowlist and NonStandardImports would always flag pickles that import at least one module). I assume this was the initial goal since it was put in a distinct file, but 3faad11 made it a transitive import and the self-registration of Analysis sub-classes enabled it. The second commit makes MLAllowlist opt-in; library users can still invoke it with:

analyzer = Analyzer([MLAllowlist()])
res = check_safety(pickled, analyzer=analyzer)

thomas-chauchefoin-tob and others added 2 commits May 26, 2026 00:58
…429)

AnalysisContext.shorten_code() mutated a shared reported_shortened_code
set as a side effect of formatting, even though most callers only wanted
the formatted string. It could then shadow findings from future analysis
runs.

For instance, UnsafeImportsML processed every import and would
leave MLAllowlist with an already-reported state for all of them.
Any import outside ML_ALLOWLIST would not be flagged by the second run.

Split shorten_code() into a pure formatter and an explicit mark_reported()
helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Analysis.__init_subclass__ put every subclass into Analysis.ALL, and
fickling/__init__.py transitively imported fickling.ml via hook.py, wich
registered MLAllowlist.

The shorten_code() shadowing bug (GHSA-cffv-grgg-g429) made it dead code
until the previous commit, and now it conflicts with other default
analysis passes.

This commit makes MLAllowlist opt-in; use `check_safety(analyze=...)`
if you need it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread test/test_analysis.py Dismissed
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