Harden Comps SharedWorker mathjs evaluation against untrusted expressions - #10
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
…ions The Comps SharedWorker evaluated the persisted, attacker-controllable comps expression with the full mathjs function set and no bounds, so a crafted expression (e.g. zeros(1e9), ones(1e6,1e6), range(0,1e12), or a recursive function assignment) could hang/OOM the worker shared across all comps consumers in a victim's browser origin. Add a hardened mathjs instance (securedMath.js) that disables the code-exec-adjacent parser functions per mathjs security guidance, enforces a function/constant allow-list, rejects user-defined function assignments, and caps expression length and parse-tree size. Validate the worker message payload shape and the expression before evaluation. Co-Authored-By: Samantha Taylor <samantha.taylor@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes
Describe your changes:
The Comps ("Derived Telemetry") SharedWorker evaluated the persisted, attacker-controllable comps expression (
configuration.comps.expression, forwarded verbatim byCompsTelemetryProvider) using the full mathjsevaluate(expression, scope)with no allow-list, length cap, or complexity bound. Because comps domain objects are shared through a common persistence store, an attacker who can create/edit acompsobject could plant an expression that, when any other user views/embeds it, forces mathjs to allocate/compute without limit (e.g.zeros(1e9),ones(1e6,1e6),range(0,1e12), or a self-recursive function assignment) — hanging/OOM-ing the SharedWorker that is shared across all comps consumers in the victim's browser origin (client-side DoS). mathjs's parser is also code-exec-adjacent (evaluate/parse/simplify/derivative/resolve/import/createUnit).Fix — a new
securedMath.jsmodule builds one hardened mathjs instance and is used by the worker:import,createUnit,reviver,evaluate,parse,simplify,derivative,resolve) viamath.import({...}, { override: true }), per mathjs security guidance. The trustedparse/evaluateare captured before the override so our own code can still use them while expressions cannot.zeros,ones,range,matrix,identity,resize,reshape,factorial,combinations, …) is excluded — any mathjs builtin not on the list is rejected.FunctionAssignmentNode) to block unbounded recursion.The worker (
CompsMathWorker.js) now:evaluate/validateExpressionfromsecuredMath.js(replacing the rawmathjsimport),expressionis a string,parametersis a well-formed array,telemetryForCompsis an object) and validates the expression once up front inassertValidCalculationPayload(...)before any telemetry point reaches the engine.Scope parameter names are always permitted as symbols, so existing valid expressions (e.g.
a*2,min(a,b),sqrt(a)) continue to work.All Submissions:
Author Checklist
src/plugins/comps/securedMathSpec.js)type:label?Link to Devin session: https://app.devin.ai/sessions/5c7df0739b2642be841185dee2c3a53e
Requested by: @samanthataylor3
Devin Review