Skip to content

Enforce read-only in pathSandbox.open#12

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits intomainfrom
dd/enforce-readonly-sandbox-open
Mar 9, 2026
Merged

Enforce read-only in pathSandbox.open#12
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits intomainfrom
dd/enforce-readonly-sandbox-open

Conversation

@AlexandreYang
Copy link
Copy Markdown
Member

What does this PR do?

Adds a defense-in-depth check in pathSandbox.open that allowlists only os.O_RDONLY. Any other flag combination is rejected with os.ErrPermission before the file is ever opened. This is safer than a denylist because it automatically rejects unknown or future flags.

Motivation

Currently, write redirections (>, >>, etc.) are blocked at AST validation time, and both internal callers (cat builtin, < redirect) only pass os.O_RDONLY. However, the sandbox open method itself had no enforcement — it passed flags straight through to os.Root.OpenFile. This means a future code change, a parser bug, or a new feature could accidentally open files for writing inside the sandbox. Rejecting everything except O_RDONLY at the sandbox layer ensures the filesystem remains read-only regardless of what happens upstream.

Testing

  • Added TestPathSandboxOpenRejectsWriteFlags covering all write flag combinations and confirming read-only still works.
  • All existing tests pass (go test ./...).

Checklist

  • Tests added/updated
  • Documentation updated (if applicable)

PR by Bits
View session in Datadog

Comment @DataDog to request changes

Co-authored-by: AlexandreYang <49917914+AlexandreYang@users.noreply.github.com>
@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented Mar 9, 2026

View session in Datadog

Bits Dev status: ✅ Done

Comment @DataDog to request changes

@AlexandreYang AlexandreYang marked this pull request as ready for review March 9, 2026 19:18
@AlexandreYang
Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 Bot commented Mar 9, 2026

View all feedbacks in Devflow UI.

2026-03-09 19:31:43 UTC ℹ️ Start processing command /merge


2026-03-09 19:31:47 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 0s (p90).


2026-03-09 19:32:24 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit a0ff655 into main Mar 9, 2026
9 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the dd/enforce-readonly-sandbox-open branch March 9, 2026 19:32
This was referenced Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants