fix(demo): validate PREWARM_REPOS before reflecting it on the demo endpoint (Closes #180) - #190
Conversation
📝 WalkthroughWalkthroughThe demo workspace controller now validates the first configured prewarm repository entry before destructuring its owner and repository segments. Invalid entries return a ChangesDemo workspace validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/src/controllers/workspace.controller.ts (1)
52-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd regression coverage for malformed repository entries.
Test missing/extra slashes, query strings, forbidden characters, and embedded line terminators. Assert the exact 503 response and that the rejected value is absent from logs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/src/controllers/workspace.controller.ts` around lines 52 - 60, Add regression tests for the repository validation branch in the controller handling PREWARM_REPOS, covering missing or extra slashes, query strings, forbidden characters, and embedded line terminators. Assert each malformed value returns the exact 503 JSON response with building set to true, and verify the rejected value is not written to logs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/src/controllers/workspace.controller.ts`:
- Around line 52-60: Add regression tests for the repository validation branch
in the controller handling PREWARM_REPOS, covering missing or extra slashes,
query strings, forbidden characters, and embedded line terminators. Assert each
malformed value returns the exact 503 JSON response with building set to true,
and verify the rejected value is not written to logs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 21f2a79f-f373-48b1-b542-4dec8bbafd72
📒 Files selected for processing (1)
backend/src/controllers/workspace.controller.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: test
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-07-24T17:54:49.155Z
Learnt from: SakethSumanBathini
Repo: harsharajkumar-273/Proofdesk PR: 112
File: backend/src/controllers/import.controller.ts:0-0
Timestamp: 2026-07-24T17:54:49.155Z
Learning: For Express controllers that run long-running work (e.g., PDF imports), handle client disconnects using `res.on('close')` and treat the connection as aborted only when `res.writableFinished === false`. Avoid using `req.on('close')` for this purpose, since it can trigger during normal request-body consumption even when the response has not completed.
Applied to files:
backend/src/controllers/workspace.controller.ts
🔇 Additional comments (1)
backend/src/controllers/workspace.controller.ts (1)
34-34: 🔒 Security & PrivacyNo end-anchor bypass here. The current regex already rejects segments with trailing line terminators, so
owner\n/repodoes not pass.> Likely an incorrect or invalid review comment.
e1568a9
into
harsharajkumar-273:main
Closes #180
Problem
GET /demois registered with no middleware (workspace.routes.ts:34), andgetDemoWorkspaceechoed operator-supplied configuration straight back to anonymous callers:Three ways that misbehaves:
owner/repo?token=xyzputs the query string intorepo, which is then returned to any unauthenticated caller — the case this issue reports.repoasundefinedand builds the cache keyowner/undefined, which silently never matches.Change
Both segments are validated against
^[A-Za-z0-9_.-]+$— the character set GitHub permits in owner and repository names — and the entry must split into exactly two parts. Anything else returns the same 503 the endpoint already uses when no build is cached, so an unauthenticated caller learns nothing about the configuration either way.Verified against the cases that matter:
The rejected value is deliberately not logged. If it contains a credential — the scenario this issue is about — writing it to the log moves the exposure rather than removing it. The log records that the value was invalid, not what it was.
Scope note
This validates what leaves the endpoint. It doesn't stop an operator putting a credential in
PREWARM_REPOSin the first place — that value is also used to drive prewarm builds elsewhere, and a malformed entry there deserves its own treatment. Happy to look at that separately if useful.Verification
npx tsc --noEmitinbackend/clean.getDemoWorkspace.Ordering
Touches
workspace.controller.ts. My open #105 branch modifiescreateTeamSessionin the same file, well away from this function — should merge, but worth landing one and re-checking.Summary by CodeRabbit