Skip to content

fix(s03,s04,s20): resolve Gate2 safe_path conflict — permission dead on write/edit - #484

Merged
Bill-Billion merged 3 commits into
mainfrom
fix/s03-gate2-safe-path-conflict
Jul 28, 2026
Merged

Bill-Billion merged 3 commits into
mainfrom
fix/s03-gate2-safe-path-conflict

Conversation

@Bill-Billion

Copy link
Copy Markdown
Collaborator

Supersedes #483. Credits to @ClearVIper3 for the initial s03 fix, extended here to s04 and s20.

Problem

In s03, Gate 2 (PERMISSION_RULES) and safe_path() used the same path check but with contradictory semantics:

  • Gate 2: soft rule — asks user "Allow? [y/N]" — answering y should permit
  • safe_path(): hard error — unconditionally raises ValueError("Path escapes workspace")

Result: user approval at Gate 2 was never effective — safe_path always blocked execution first.

The same bug exists in s04_hooks and s20_comprehensive.

Fix

  • Delete safe_path — path safety is now solely the permission layer's responsibility
  • Inline path resolution in run_read, run_write, run_edit via (WORKDIR / path).resolve()
  • Add read_file to Gate 2 coverage (previously only write_file/edit_file)
  • Rename message to "Access outside workspace" (was "Writing", now covers reads)
  • Sync READMEs (all 3 languages per module)

Files changed

s03_permission/code.py: Delete safe_path, inline paths, expand Gate 2 to read_file
s03_permission/README..md (3): Update Gate 2 table + code snippet
s04_hooks/code.py: Same fix: delete safe_path, inline paths, expand permission_hook
s04_hooks/README.
.md (3): Update permission_hook snippet
s20_comprehensive/code.py: Same fix + replace safe_path-based try/except with user prompt
s20_comprehensive/README.*.md: (no snippet to update)

Intentionally NOT changed

s05~s08: their permission_hook only checks bash deny list — path checking is absent from the permission layer. safe_path is their only path defense and must stay.

Closes #482

root added 3 commits July 28, 2026 17:47
…/edit

Gate 2 (PERMISSION_RULES) and safe_path() used the same path check:
(WORKDIR / path).resolve().is_relative_to(WORKDIR)

But gave contradictory semantics:
- Gate 2: soft rule, user-approvable
- safe_path: hard ValueError, unbypassable

Result: user approval at Gate 2 was never effective;

1. Remove hard error from safe_path, keep only str->Path
2. Inline path resolution in run_read/run_write/run_edit
3. Add read_file to PERMISSION_RULES coverage

Closes #482
s04_hooks: permission_hook checks path + asks user, but safe_path
still raised hard ValueError — user approval was ineffective, same
root cause as s03 (#482).

s20_comprehensive: permission_hook used safe_path directly inside
try/except, silently denying all writes outside workspace without
ever asking the user.  Now uses is_relative_to check + user prompt.

Both files also add read_file to the permission coverage.

s05-s08 intentionally NOT changed: their permission_hook does not
check paths at all — safe_path is their only path-safety defense.
- Delete safe_path entirely (following PR #483 approach) — no dead code
- Update all 3 READMEs per module to reflect read_file in Gate 2
- s04: also update permission_hook snippet in READMEs
- s20: remove safe_path (already replaced with inline resolution)

Closes #482
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
learn-claude-code c959829 Jul 28 2026, 11:39 AM

@Bill-Billion
Bill-Billion merged commit c4ff380 into main Jul 28, 2026
3 of 6 checks passed
Bill-Billion added a commit that referenced this pull request Jul 28, 2026
…lict

fix(s03,s04,s20): resolve Gate2 safe_path conflict — permission dead on write/edit

Co-authored-by: Viper <41693046+ClearVIper3@users.noreply.github.com>
@Bill-Billion
Bill-Billion deleted the fix/s03-gate2-safe-path-conflict branch July 28, 2026 14:37
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.

s03: Gate2「写工作区外」规则与 safe_path 语义冲突,Permission在Write和Edit上失效

1 participant