Skip to content

Fix math_animate scan bypass via re-exported modules (fixes #864) - #865

Open
adeeluddin01 wants to merge 1 commit into
calesthio:mainfrom
adeeluddin01:fix/math-animate-scan-reexport-864
Open

adeeluddin01 wants to merge 1 commit into
calesthio:mainfrom
adeeluddin01:fix/math-animate-scan-reexport-864

Conversation

@adeeluddin01

Copy link
Copy Markdown

Summary

Fixes #864. The math_animate safety scan checked import roots against a
denylist, but did not account for standard-library modules that re-export a
blocked module as an attribute. import zipfile is not blocked, and
zipfile.os is the real os module, so a scene could reach host command
execution while the scan reported zero violations — on the default path,
without allow_unsafe_code.

What changed (tools/graphics/math_animate.py)

The scan (_scan_scene_code) gains three rules. All existing
denylist / blocked-name / dunder rules and their messages are unchanged.

  1. Re-exported module attribute access is a violation. An attribute
    access whose name is itself a blocked module, rooted on a name bound by
    an import, is flagged — e.g. zipfile.os, tarfile.os, chained forms,
    aliased imports (import zipfile as z; z.os), and rebinding forms
    (x = zipfile; x.os). Taint from imports propagates through plain
    rebinding assignments so rebinding does not hide the module.
  2. Importing a blocked name from any module is a violation — e.g.
    from zipfile import os.
  3. Star-imports from modules other than manim are violations — e.g.
    from zipfile import * (which would otherwise bind unknown names,
    possibly a blocked module, without any import node naming them).
    from manim import * stays allowed: it is how scenes get Manim's API.

A small helper, _attr_root_name, resolves the root name of an attribute
chain for rule 1.

Tests (tests/tools/test_math_animate_safety.py)

7 new regression tests for #864:

  • test_blocks_os_via_reexported_module (zipfile.os, top level)
  • test_blocks_os_via_reexport_inside_construct (tarfile.os)
  • test_blocks_aliased_reexport (import zipfile as z)
  • test_blocks_reexport_via_rebinding (x = zipfile; x.os)
  • test_blocks_from_import_of_blocked_name (from zipfile import os)
  • test_blocks_star_import_from_non_manim (from zipfile import *)
  • test_safe_scene_attribute_access_still_passes

Full suite run locally against the fixed module: 27 passed
(20 existing + 7 new). The existing safe scene (manim + numpy +
math, using np.pi / math.tau) still passes, so legitimate scenes are
unaffected — no breaking change.

Scope notes (honest)

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.

math_animate safety scan bypass: unblocked stdlib module re-exports os, allowing host command execution on the default path

1 participant