Skip to content

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

Merged
thomas-chauchefoin-tob merged 2 commits into
masterfrom
fix/ghsa-cffv-grgg-g429-mlallowlist-shadowing
Jun 24, 2026
Merged

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

Conversation

@thomas-chauchefoin-tob

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

Copy link
Copy Markdown
Collaborator

@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)

Comment thread test/test_analysis.py Dismissed
thomas-chauchefoin-tob and others added 2 commits June 25, 2026 01:11
)

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>
@thomas-chauchefoin-tob thomas-chauchefoin-tob force-pushed the fix/ghsa-cffv-grgg-g429-mlallowlist-shadowing branch from 6eeadbb to f10380c Compare June 24, 2026 23:11
@thomas-chauchefoin-tob thomas-chauchefoin-tob merged commit 41ce7cb into master Jun 24, 2026
11 checks passed
@thomas-chauchefoin-tob thomas-chauchefoin-tob deleted the fix/ghsa-cffv-grgg-g429-mlallowlist-shadowing branch June 24, 2026 23:16
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