← Back to Pull requests

fix(api): prevent tools command injection #13

Open
majestic-owl448 opened this pull request with 1187 lines diff across 12 files
View on GitHub
majestic-owl448 majestic-owl448 commented on Sep 16, 2026 08:04 UTC
Author

Checklist:

<!-- Please follow this checklist and put an x in each of the boxes, like this: [x]. It will ensure that our team takes your pull request seriously. -->

  • I have read freeCodeCamp's contribution guidelines.

  • My pull request has a descriptive title (not a vague title like Update index.md)
  • <!-- Feel free to add any additional description of changes below this line -->

    The tools API interpolates request parameters into shell commands. Replace shell execution with separate executable arguments and a working directory, validate block paths and positive integer step numbers, and reject inherited command names. Preserve subprocess output in JSON error responses.

    Validation: six regression tests pass, including a real pnpm working-directory check. API type checking, lint, and formatting pass.

    Diff: 1187 lines (+1122 / -65) across 12 files Reviewer: ojeytonwilliams Review duration: 62969m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.66) × (1 − Review Confidence (0.78)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.66 · 1187 lines diff across 12 files
    0.66
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.67 · 3 substantive comment(s)
    0.67
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    78%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Real PR Conversation Timeline
    6 items
    ojeytonwilliams ojeytonwilliams requested changes on Sep 16, 2026 13:59 UTC
    Changes Requested Reviewer

    The tests are complicated and hard to follow. Rather than e2e tests, it would be easier to understand if the tests were focused on the issues we care about.

    It doesn't make a ton of sense to rely on integration tests - it would be better to have just one ("command injection is blocked", say) and then cover the rest with unit tests. For example, we could have a validator that takes in all the input (block, command and num) and returns a valid { block, command, num } object. Then the validator can be tested in isolation and its output used safely. That sort of thing.

    Also, if something has to be integration tested, then supertest is probably the way to go.

    Finally, node:test still seems to have a poor DX when compared to vitest, so I would just use vitest.

    ojeytonwilliams ojeytonwilliams commented on Sep 16, 2026 14:39 UTC
    Contributor

    Oh, I forgot a couple of things, sorry.

    We don't need to support windows, imo. I don't think anyone on the team uses it, so it's a pain to debug and errors likely go unnoticed.

    Also, the tests would need adding to CI. e.g. turbo config, root test script + workflow.

    socket-security[bot] socket-security[bot] commented on Sep 16, 2026 15:16 UTC
    Bot

    Review the following changes in direct dependencies. Learn more about Socket for GitHub.

    <table>
    <thead>
    <tr>
    <th>Diff</th>
    <th width="200px">Package</th>
    <th align="center" width="100px">Supply Chain<br/>Security</th>
    <th align="center" width="100px">Vulnerability</th>
    <th align="center" width="100px">Quality</th>
    <th align="center" width="100px">Maintenance</th>
    <th align="center" width="100px">License</th>
    </tr>
    </thead>
    <tbody>
    <tr><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101925417447"><img src="https://github-app-statics.socket.dev/diff-added.svg" title="Added" alt="Added" width="20" height="20"></a></td><td><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101925417447">@​types/​supertest@​7.2.1</a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101925417447"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Supply Chain Security" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101925417447"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Vulnerability" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101925417447"><img src="https://github-app-statics.socket.dev/score-72.svg" title="Quality" width="40" height="40" alt="72"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101925417447"><img src="https://github-app-statics.socket.dev/score-81.svg" title="Maintenance" width="40" height="40" alt="81"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101925417447"><img src="https://github-app-statics.socket.dev/score-100.svg" title="License" width="40" height="40" alt="100"></a></td></tr>
    <tr><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101947251776"><img src="https://github-app-statics.socket.dev/diff-added.svg" title="Added" alt="Added" width="20" height="20"></a></td><td><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101947251776">vitest@​5.0.1</a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101947251776"><img src="https://github-app-statics.socket.dev/score-98.svg" title="Supply Chain Security" width="40" height="40" alt="98"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101947251776"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Vulnerability" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101947251776"><img src="https://github-app-statics.socket.dev/score-79.svg" title="Quality" width="40" height="40" alt="79"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101947251776"><img src="https://github-app-statics.socket.dev/score-98.svg" title="Maintenance" width="40" height="40" alt="98"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101947251776"><img src="https://github-app-statics.socket.dev/score-100.svg" title="License" width="40" height="40" alt="100"></a></td></tr>
    <tr><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101945704767"><img src="https://github-app-statics.socket.dev/diff-added.svg" title="Added" alt="Added" width="20" height="20"></a></td><td><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101945704767">vite@​8.3.0</a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101945704767"><img src="https://github-app-statics.socket.dev/score-99.svg" title="Supply Chain Security" width="40" height="40" alt="99"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101945704767"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Vulnerability" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101945704767"><img src="https://github-app-statics.socket.dev/score-82.svg" title="Quality" width="40" height="40" alt="82"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101945704767"><img src="https://github-app-statics.socket.dev/score-97.svg" title="Maintenance" width="40" height="40" alt="97"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101945704767"><img src="https://github-app-statics.socket.dev/score-100.svg" title="License" width="40" height="40" alt="100"></a></td></tr>
    <tr><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101856924554"><img src="https://github-app-statics.socket.dev/diff-added.svg" title="Added" alt="Added" width="20" height="20"></a></td><td><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101856924554">supertest@​7.2.2</a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101856924554"><img src="https://github-app-statics.socket.dev/score-99.svg" title="Supply Chain Security" width="40" height="40" alt="99"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101856924554"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Vulnerability" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101856924554"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Quality" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101856924554"><img src="https://github-app-statics.socket.dev/score-87.svg" title="Maintenance" width="40" height="40" alt="87"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/freeCodeCamp/diff-scan/2c298f5c-4fad-4827-bf63-ea07c6eb7178?tab=dependencies&dependency_item_key=101856924554"><img src="https://github-app-statics.socket.dev/score-100.svg" title="License" width="40" height="40" alt="100"></a></td></tr>
    </tbody>
    </table>

    View full report

    <!-- overview-comment -->

    ojeytonwilliams ojeytonwilliams commented on Sep 16, 2026 17:12 UTC
    Contributor

    Thanks, @majestic-owl448, that's heaps better. I'll try to re-review again tomorrow.

    ojeytonwilliams ojeytonwilliams approved these changes on Sep 17, 2026 14:55 UTC
    Approved Reviewer

    LGTM 👍 Thanks, @majestic-owl448

    Assignees
    majestic-owl448 majestic-owl448
    Labels
    risk: low confidence: 78.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 66.1% (HIGH) · Higher = larger blast radius
    66.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 78.5% · Lower = rushed or shallow review
    78.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.2% · Safe to merge
    14.2%