test(WriteTool.write): File permissions respect user's umask#21233
test(WriteTool.write): File permissions respect user's umask#21233HaleTom wants to merge 2 commits intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
These two PRs are complementary—PR #21233 stabilizes the test, and PR #19077 fixes the production code. Check if both are needed or if there's overlap in scope. |
There was a problem hiding this comment.
Pull request overview
Makes the tool.write permission-related test deterministic across environments by controlling the process umask during the assertion.
Changes:
- Wraps the sensitive-file permission assertion in a
process.umask(0o022)/ restore block to avoid failures under non-default host umasks.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
9719a21 to
3fcdc4a
Compare
3fcdc4a to
90f7ec2
Compare
Issue for this PR
Fixes #19076 while respecting user's umask
Type of change
What does this PR do?
The
writetool testsets file permissions when writing sensitive datafails on systems with a non-default umask (e.g.0027). The test hardcodes0o644as the expected permission, butFilesystem.write()respects the system umask when no explicit mode is set.This wraps the permission test in
process.umask(0o022)/finally { process.umask(prevUmask) }so the assertion is deterministic regardless of the host environment.Why force umask in the test, not in production code?
PR #19077 attempts to fix this by forcing
0o644on all files via a post-writechmodto bypass umask filtering. This is a security regression — a user runningumask 077has intentionally restricted their environment so new files are0600(owner-only). Forcing0o644programmatically loosens their security boundary and makes all AI-written files world-readable, including.envfiles, credentials, or private keys.You should never programmatically loosen a user's umask — it's a deliberate security boundary. The correct approach is to respect it, or chmod to something more restrictive (e.g.,
0600for sensitive files), never less.With #14853 closed by its author, there's no remaining reason to override or loosen a user's umask in the write tool. I'd gently suggest closing both #19076 and #19077.
How did you verify your code works?
bun test test/tool/write.test.ts— all 13 tests passbun typecheck— no errorsumask 077andumask 022— both passScreenshots / recordings
N/A — no UI changes.
Checklist