fix: confine event hook script paths to the project tree - #4133
Merged
mnriem merged 2 commits intoAug 17, 2026
Conversation
Event dispatch joined the first scripts: token onto the .specify or extension base with Path. An absolute token discarded the base and ran a host binary. Reject anchored tokens and require the resolved path to stay inside the project root. Assisted-by: Grok (model: grok-4.6, supervised) Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
mnriem
requested changes
Aug 17, 2026
mnriem
left a comment
Collaborator
There was a problem hiding this comment.
Please address Copilot feedback
Generated dispatchers only delegate when EVENT_SCRIPT_PATH_CONFINEMENT is True, so an older global install cannot bypass the project-tree guard. Assisted-by: Grok (xAI, under direct human supervision) Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Contributor
Author
Addressed in 4c3361b. The dispatcher no longer delegates to an older installed Posted on behalf of @SebTardif by Grok (xAI). |
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
src/specify_cli/events.py:105
- On supported Python 3.11/3.12,
Path.resolve()raisesRuntimeErrorfor a symlink loop. Because_resolve_argv()runs before the fallback's executiontry, a loop in a script path escapes as a dispatcher traceback instead of being rejected like the other path-resolution failures. CatchRuntimeErrorhere so the generated dispatcher continues to fail closed.
This issue also appears on line 586 of the same file.
try:
root = project_root.resolve()
candidate = (base / token).resolve()
candidate.relative_to(root)
except (OSError, ValueError):
return None
src/specify_cli/events.py:591
Path.resolve()can raiseRuntimeErrorfor symlink loops on supported Python 3.11/3.12. This resolver is called beforeresolve_and_run_event_command()enters its subprocess exception boundary, so such a token leaks a traceback rather than degrading to “no runnable script.” IncludeRuntimeErrorin the confinement failure handling, matching the generated helper.
try:
root = project_root.resolve()
candidate = (base / token).resolve()
candidate.relative_to(root)
except (OSError, ValueError):
return None
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Balanced
mnriem
self-requested a review
August 17, 2026 20:51
mnriem
approved these changes
Aug 17, 2026
Collaborator
|
Thank you! |
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.
Description
Event hook script resolution joined the first
scripts:token onto the.specifyor extension base withPath. An absolute token discarded that base and ran a host binary.This rejects anchored tokens (absolute, drive, UNC) and requires the resolved path to stay inside the project root. Relative
..walks that remain in the project still work, including documented extension../../scripts/...references to core scripts. The same check is in the CLI resolver and the generated stdlib dispatcher.Introduced in #3704 (
f8e474d, 2026-07-29).Same-repo path confinement: #3088, #2296, #3869.
Closes #4131
Testing
uv run specify --helpuv sync && uv run pytest(tests/integrations/test_events.py, 121 passed)Added resolver tests for absolute tokens, a walk out of the project, Windows-anchored tokens, extension
../../scripts/..., symlink escape, and an inline-dispatcher run that refuses an absolute host script.AI Disclosure
Code and tests written with Grok (model: grok-4.6) under direct supervision. Reviewed and tested locally before opening this PR.
Posted on behalf of @SebTardif by Grok (model: grok-4.6).