Skip to content

fix(pm-dispatch): scope sessions directory to REPO_DIRS for OIDC callers (#2903) - #2907

Merged
dezren39 merged 2 commits into
mainfrom
queue/4132-2903-directory-scope
Oct 31, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/4132-2903-directory-scope

Conversation

@dezren39

@dezren39 dezren39 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Closes #2903.

OIDC callers could pass any directory to POST /v1/sessions and get a session anywhere on the laptop, escaping the repo allowlist entirely. resolveSessionDirectory() (new in validate.ts, unit-tested) now restricts OIDC callers to omitted (= repo primary clone) or exactly the repo clone, enforced in handleSessions before the tracking issue, queue task, or session is created (400 otherwise). Bearer callers keep the free-form directory as a deliberate documented choice (README). Trailing slashes are normalized.

Tests: bun test in pm-stack/dispatch — 46 pass, 0 fail (7 new scoping cases). bunx tsc --noEmit fails identically on clean main (missing bun types — pre-existing/environmental).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner October 31, 2026 01:46
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 862349d5-0636-4f6f-b743-e13e20c4538b
Commits

Reviewing files that changed from the base of the PR and between 2a66b4d and b1d7a8e.

Files selected for processing: 5
  • pm-stack/dispatch/README.md
  • pm-stack/dispatch/src/server.ts
  • pm-stack/dispatch/src/validate.ts
  • pm-stack/dispatch/test/server.test.ts
  • pm-stack/dispatch/test/validate.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T01:54:39.854368Z b1d7a8e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99dd7fff4f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Directory scoping (issue #2903) runs before ANY side effect: the
// tracking issue, queue task and session below are all created after
// this line, so a rejected directory leaves nothing behind.
const directory = resolveSessionDirectory(caller.type, body.repo, body.directory, REPO_DIRS);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Catch directory-validation failures at the HTTP boundary

For an authenticated OIDC request specifying a foreign directory, this new validation rejects the request but does not return the documented HTTP 400. The routing handler returns the handleSessions promise without awaiting it inside its try, so the ValidationError bypasses its catch block and reaches Bun as an unhandled handler rejection, producing HTTP 500 instead. Await the session handler within that error boundary and add an HTTP-level rejection test; the current unit tests only verify that the helper throws.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1d7a8e: both handlers are now awaited inside the error boundary so the directory ValidationError maps to the documented HTTP 400, and test/server.test.ts pins it end-to-end (OIDC + foreign directory → 400 with no side effect possible; omitted/own-clone → passes validation). Server entry is also guarded by import.meta.main so tests can import the handler without binding ports.

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.

fix(pm-dispatch): POST /v1/sessions accepts an arbitrary directory — OIDC callers escape their repo clone

1 participant