Skip to content

fix: block unsafe low-level stdlib imports - #349

Open
DilipMallavarapu wants to merge 4 commits into
trailofbits:masterfrom
DilipMallavarapu:fix/unsafe-stdlib-imports
Open

DilipMallavarapu wants to merge 4 commits into
trailofbits:masterfrom
DilipMallavarapu:fix/unsafe-stdlib-imports

Conversation

@DilipMallavarapu

Copy link
Copy Markdown

Summary

  • Add fcntl, termios, resource, and msvcrt to UNSAFE_IMPORTS to flag potentially unsafe standard library calls.
  • Add regression tests covering all four modules.

Testing

  • Full test suite: 153 passed.
  • Ruff formatting and lint checks passed.

@CLAassistant

CLAassistant commented Nov 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! Could you please sign the contributor license agreement? We’ll need the signed CLA before we can review and merge this PR.

@DilipMallavarapu

Copy link
Copy Markdown
Author

I tried to sign the agreement yesterday but due to some rate limiting issues I couldn't sign it, I checked it now and signed it! Thanks :)

ESultanik
ESultanik previously approved these changes Nov 5, 2026

@dguido dguido left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] fickling/fickle.py:249 blocks termios.tcsetattr, but tty.tcsetattr is the same function on Unix. A pickle importing it through tty receives LIKELY_SAFE from check_safety(). Please block the relevant tty exports and add an alias-path regression test.

@DilipMallavarapu

Copy link
Copy Markdown
Author

Good catch @dguido ! Confirmed on Python 3.12 that tty re-exports the termios functions via from termios import *, so tty.tcsetattr and the other affected functions resolve to the same objects. Added the six unsafe tty aliases to UNSAFE_GLOBALS and regression tests covering the tty import paths. Left the read-only tcgetattr and tcgetwinsize out to avoid false positives.

Fixed in 3fdf2dc. Thanks for the review!

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants