Repository navigation
feat(bson-parsing): restrict web worker scope COMPASS-11128 - #892
Conversation
| // Used by this file. | ||
| 'self', | ||
| 'onmessage', | ||
| 'postMessage', |
There was a problem hiding this comment.
Adding const { self, onmessage, postMessage } = globalThis; above this statement should remove this requirement, and we do want to avoid a situation where the "sandbox" could call postMessage()
There was a problem hiding this comment.
Yes, that's much better and will clean this up
| 'parseInt', | ||
| 'encodeURIComponent', | ||
| 'decodeURIComponent', | ||
| 'Buffer', |
There was a problem hiding this comment.
Buffer is a Node.js concept, do we need that?
There was a problem hiding this comment.
It was added to support the usage around LegacyUUID in scope.ts. I switched to bson.ByteUtils instead in 4623dfa.
Also, now that we added support for node as well, I've to keep it as web-worker package relies on it
There was a problem hiding this comment.
Hi @mabaasit, the ticket says to remove Node globals, but the PR’s allowlist still includes both process and Buffer. The comment says process is needed by the web-worker package. You mentioned the code switched to bson.ByteUtils instead of Buffer (I can't open 4623dfa link - if it's addressed there). Confirming whether Buffer is still needed and whether keeping process is an acceptable exception to the task’s security goal.
| '__defineSetter__', | ||
| '__lookupGetter__', | ||
| '__lookupSetter__', | ||
| 'constructor', |
There was a problem hiding this comment.
Object.prototype.constructor is part of standard JS, why are we excluding that?
b1f6d4c to
2460ab7
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The worker response callback can break, and test environment cleanup is incorrect.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This pull request hardens the BSON parser web worker by restricting its scope and expanding worker tests.
Changes:
- Restricts worker globals and prototypes.
- Supports direct worker URLs in tests.
- Adds worker lifecycle and security coverage.
| File | Summary |
|---|---|
packages/shell-bson-parser/src/worker.ts |
Restricts worker capabilities. Critical (3 votes): postMessage must remain available. |
packages/shell-bson-parser/src/worker-client.ts |
Adds test worker URL handling. |
packages/shell-bson-parser/src/index.spec.ts |
Expands worker behavior tests. Moderate (1 vote): delete the environment variable instead of assigning undefined. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
2460ab7 to
b4a5690
Compare
b4a5690 to
a1d77b8
Compare
a1d77b8 to
9442c14
Compare
|
Assigned |
c8d93e9 to
9ca9089
Compare
6c62c27 to
43001aa
Compare
fe7be76 to
e9934b1
Compare
660996f to
3b999a9
Compare
3b999a9 to
4ac37a8
Compare
4ac37a8 to
8120d01
Compare
| 'Map', | ||
| 'Set', | ||
| 'WeakMap', | ||
| 'WeakSet', |
There was a problem hiding this comment.
Based on what data is the full allow list constructed?
I could see "console" isn't in allow list. Could be the case web-worker's Node shim calls console.error when a handler throws, which would turn errors into confusing ReferenceErrors.
There was a problem hiding this comment.
This list is based on the current tests, integration with compass, globals needed for parsing etc.
Nice catch with console. I'll add that to this list
LuciaHarcekova
left a comment
There was a problem hiding this comment.
Approved.
The core approach looks solid. The allowlist-then-delete pattern is appropriate, and Object.getOwnPropertyNames correctly includes non-enumerable globals. restrictObjectPrototype is also a valuable layer of protection against prototype-pollution gadgets.
I verified that require, global, fetch, eval, XMLHttpRequest, WebAssembly, and setTimeout are removed. Thanks for addressing the review feedback, including switching from Buffer to bson.ByteUtils and capturing postMessage before restricting the global scope.
nit: please update the PR description with links to the relevant data and a brief note mapping the requirements from those sources to the implementation, so reviewers can verify that the full scope is covered.
9c092b3 to
3d91aa4
Compare
3d91aa4 to
f67a2de
Compare
f67a2de to
d45ff0c
Compare

Description
COMPASS-11128
Open Questions
Checklist
Stack created with GitHub Stacks CLI • Give Feedback 💬