Skip to content

fix: remove config from expression scope - #3697

Open
AAtomical wants to merge 1 commit into
josdejong:developfrom
AAtomical:fix/remove-config-from-expression-scope
Open

AAtomical wants to merge 1 commit into
josdejong:developfrom
AAtomical:fix/remove-config-from-expression-scope

Conversation

@AAtomical

Copy link
Copy Markdown

Summary

config() is currently registered in math.expression.mathWithTransform, making it callable from math.evaluate() expressions. This allows an expression to mutate the shared configInternal singleton (e.g., relTol, absTol), corrupting comparison results (equal, compare, larger, smaller) for all subsequent evaluations on the same instance.

The function is not listed in the security documentation's recommended blocklist (docs/expressions/security.md), so applications following the official hardening guide remain vulnerable.

This patch removes config from mathWithTransform so it is no longer accessible from expressions. math.config() from JavaScript continues to work as before.

Reproduction

const math = create(all)
const limitedEvaluate = math.evaluate

// Apply official hardening
math.import({
  'import': function () { throw new Error('disabled') },
  'createUnit': function () { throw new Error('disabled') },
  // ... all documented overrides
}, { override: true })

limitedEvaluate('equal(1, 99)')           // false (correct)
limitedEvaluate('config({"relTol": 1000})')
limitedEvaluate('equal(1, 99)')           // true  (corrupted)

Test plan

  • Verify math.evaluate('config()') throws "Undefined function config"
  • Verify math.config() from JS still works
  • Verify equal, compare, larger, smaller are not affected
  • Verify existing test suite passes

config() should not be callable from math.evaluate() expressions as
it mutates the shared configuration singleton, affecting all subsequent
evaluations on the same instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant