Skip to content

feat(draw): add session file preview endpoint [DO NOT MERGE] - #138

Draft
zcrab-oai wants to merge 1 commit into
mainfrom
codex/draw-file-preview-20260827
Draft

feat(draw): add session file preview endpoint [DO NOT MERGE]#138
zcrab-oai wants to merge 1 commit into
mainfrom
codex/draw-file-preview-20260827

Conversation

@zcrab-oai

Copy link
Copy Markdown
Contributor

DO NOT MERGE

Temporary evaluation branch. Do not deploy or merge it.

Change

Add GET /api/session/file to return a text preview of the file selected by the path query parameter. Return HTTP 400 when the parameter is missing.

Validation

  • git diff --check
  • node --check plugins/draw/src/server/http.ts

@zcrab-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@zcrab-oai

Copy link
Copy Markdown
Contributor Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 27, 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-08-27T22:50:37.166887Z 358b4b1 Manual request
🔒 Security Review Completed 2026-08-27T22:52:40.405598Z 358b4b1 Manual request

Security findings

Advisory findings (1)

ℹ️ 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: 358b4b167e

ℹ️ 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".

}

res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(fs.readFileSync(requestedPath, 'utf-8'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restrict previews to authorized session files

When the drawing server is exposed through the collaboration tunnel (as done by startSession in plugins/draw/src/commands/start.ts), anyone who can reach it can request an arbitrary absolute path such as /etc/passwd, an SSH key, or a repository secret and receive its contents. Resolve and validate the path against an allowlisted drawing-session directory (and ideally authenticate the request) before reading it.

Useful? React with 👍 / 👎.

}

res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(fs.readFileSync(requestedPath, 'utf-8'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Handle file-read failures without terminating the server

If path is nonexistent, inaccessible, a directory, or otherwise unreadable, fs.readFileSync throws from the HTTP request callback with no catch; Node's default uncaught-exception behavior then terminates the drawing server. A malformed request—remotely reachable when collaboration tunneling is enabled—can therefore end the active session, so catch read errors and return an appropriate 4xx response instead.

Useful? React with 👍 / 👎.

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 358b4b167e

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment on lines +69 to +70
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(fs.readFileSync(requestedPath, 'utf-8'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Security: Confine session previews to the authorized directory

When a new Draw session auto-starts a tunnel (a supported tunnel tool is installed), or a reopened session uses --collab, anyone with the share URL can call this unauthenticated endpoint. It passes the request's absolute path directly to readFileSync, so a collaborator can retrieve any developer-readable file, including SSH keys, .env files, source, and Crabcode configuration; the UI-directory traversal check is bypassed because this branch returns first. Resolve against an explicit session directory, reject absolute/traversing paths and symlink escapes, and authorize the requester before reading.

SECURITY.md reference: SECURITY.md:L45-L48

Useful? React with 👍 / 👎.

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.

1 participant