fix(api): prevent tools command injection #13
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.
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.
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>
<!-- overview-comment -->
Thanks, @majestic-owl448, that's heaps better. I'll try to re-review again tomorrow.
LGTM 👍 Thanks, @majestic-owl448
ojeytonwilliams
majestic-owl448
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. -->
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.