feat: audit tool for allow_functions#9463
Draft
pjwerneck wants to merge 4 commits into
Draft
Conversation
pjwerneck
force-pushed
the
pjwerneck/restrict-allowed-audit
branch
from
July 23, 2026 12:15
7051dd4 to
a23e10c
Compare
pjwerneck
force-pushed
the
pjwerneck/restrict-allowed-audit
branch
2 times, most recently
from
July 23, 2026 19:30
95afe4c to
25b2a2a
Compare
… audit, and test files
pjwerneck
force-pushed
the
pjwerneck/restrict-allowed-audit
branch
from
July 23, 2026 19:33
25b2a2a to
12d03f9
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an advisory “allow-list audit” capability to syft-restrict so reviewers can see whether allow_functions entries are considered safe/dual-use/unsafe (or deferred to “review”) based on an external, curated catalog, without changing the verifier’s pass/fail behavior.
Changes:
- Introduces
syft_restrict.auditor(audit_allow_functions,AuditReport,PathAudit) and wires the audit report intorunner.RunResult.audit(pluscatalog_dirparameter). - Adds a catalog linter CLI (
syft-restrict-lint) and example catalogs for JAX/Flax plus cross-library_commonpatterns. - Adds unit tests covering audit classification, catalog version matching, linting behavior, and
run()audit attachment semantics.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/syft-restrict/tests/test_run.py | Adds tests asserting RunResult.audit is attached and remains advisory (doesn’t change ok). |
| packages/syft-restrict/tests/test_auditor.py | New tests for audit verdicts, version-dir matching, and catalog linter --fix behavior. |
| packages/syft-restrict/src/syft_restrict/runner.py | Attaches an advisory audit report to RunResult and adds catalog_dir plumbing. |
| packages/syft-restrict/src/syft_restrict/catalog_lint.py | Adds a CLI linter to canonicalize/validate catalog.json formatting. |
| packages/syft-restrict/src/syft_restrict/auditor.py | Implements catalog-based allow-list classification and report formatting. |
| packages/syft-restrict/src/syft_restrict/init.py | Exposes audit API (audit_allow_functions, AuditReport, PathAudit) at the package top level. |
| packages/syft-restrict/README.md | Documents the new auditor concept and usage guidance around globs vs tight allows. |
| packages/syft-restrict/pyproject.toml | Registers syft-restrict-lint console script entrypoint. |
| packages/syft-restrict/examples/catalog/jax/0.11/catalog.json | Adds example JAX 0.11 risk catalog (safe/dual-use/unsafe). |
| packages/syft-restrict/examples/catalog/flax/0.12/catalog.json | Adds example Flax 0.12 (linen) risk catalog. |
| packages/syft-restrict/examples/catalog/_common/default/catalog.json | Adds cross-library unsafe patterns (e.g., *.tofile, *.io_callback) and orbax blanket rule. |
| packages/syft-restrict/docs/blacklist.md | Updates guidance about preferring tight allow_functions and risks of globs. |
| packages/syft-restrict/docs/audit.md | New documentation for audit verdicts and catalog layout/workflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+201
to
+213
| def _detect_versions(paths) -> dict[str, str]: | ||
| versions: dict[str, str] = {} | ||
| for path in paths: | ||
| root = path.split(".", 1)[0].lstrip("*") | ||
| if not root or root in versions: | ||
| continue | ||
| try: | ||
| mod = importlib.import_module(root) | ||
| except ImportError: | ||
| versions[root] = "not installed" | ||
| else: | ||
| versions[root] = getattr(mod, "__version__", "unknown") | ||
| return versions |
Comment on lines
+168
to
+173
| def _load_ruleset(root: Path, library: str, version_dir: str) -> dict: | ||
| """Read ``<root>/<library>/<version_dir>/catalog.json``; empty dict if the file is absent.""" | ||
| path = root / library / version_dir / "catalog.json" | ||
| if not path.is_file(): | ||
| return {} | ||
| return json.loads(path.read_text()) |
Comment on lines
+18
to
+20
| - **The auditor** checks the allow-list of library calls and operators against a | ||
| catalog of known safe/dual-use/unsafe paths, and warns on any uncatalogued | ||
| paths. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a catalog of commonly used jax/flax functions categorized by risk, and an audit tool to check
allow_functionsagainst the catalog.Changes
Testing
Asana task
https://app.asana.com/1/1185126988600652/project/1216249688888494/task/1216819877469865?focus=true