FicklingMLUnpickler Shallow-Copies ML_ALLOWLIST

Open Beginner friendly
#355 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in fickling/ml.py: FicklingMLUnpickler.__init__ builds its allowlist with dict(ML_ALLOWLIST), which leaves the inner per-module dicts shared with the global. Read how also_allow mutates those inner dicts, then reproduce with the snippet in the issue to confirm collections.Counter leaks into ML_ALLOWLIST. Pick one of the two proposed fixes (deep copy on init, or copy-on-write), add a regression test proving a second unpickler does not see the first one's also_allow entries, and run the ML test suite. Done means the global ML_ALLOWLIST and other unpicklers are unchanged after an instance allows something extra.

Written by the indexing model from the issue text.

Description

When an unpickler instance is created, FicklingMLUnpickler.init copies ML_ALLOWLIST using dict(ML_ALLOWLIST), which is a shallow copy. The per-module inner dicts are still shared with the global. So when also_allow is used to expand the allowlist for a module already in ML_ALLOWLIST, the global dict is altered instead of a local copy, this causes all unpicklers and even the scanner to unintentionally allowlist it.

Tested and reproduced on the latest commit on the master branch.

import io
from fickling.ml import FicklingMLUnpickler, ML_ALLOWLIST

print("Before:", "Counter" in ML_ALLOWLIST.get("collections", {}))
_ = FicklingMLUnpickler(io.BytesIO(b""), also_allow=["collections.Counter"])
print("After :", "Counter" in ML_ALLOWLIST.get("collections", {}))

Initially reported this as a security disclosure but was instructed to report as a public issue instead.

Possible fixes:
1: Just changing the copying to a deep copy, so each unpickler has its own instance of the allowlist
2: Copy on write, so we do a deepcopy of the allowlist only when its altered

image

Lmk which one sounds better :)

Dominant language
Python
Stars
678
Forks
89
Avg merge
41m
Merged PRs (30d)
14

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from trailofbits/fickling

All issues in trailofbits/fickling

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.