Skip to content

security: replace eval() in RPN unary math functions with safe dispatch (GHSA-4mmp-mv2x-m9f6) - #808

Open
bmfmancini wants to merge 3 commits into
developfrom
advisory-fix-eval-funcs
Open

security: replace eval() in RPN unary math functions with safe dispatch (GHSA-4mmp-mv2x-m9f6)#808
bmfmancini wants to merge 3 commits into
developfrom
advisory-fix-eval-funcs

Conversation

@bmfmancini

Copy link
Copy Markdown
Member

Security Fix — GHSA-4mmp-mv2x-m9f6

Fixes GHSA-4mmp-mv2x-m9f6

Summary

The thold_expression_math_rpn() function in thold_functions.php used PHP's eval() to evaluate unary math functions (line 403) during RPN expression parsing for threshold expressions.

Vulnerability Details

  • Rule: php:S1523 (SonarQube)
  • CWE: CWE-95 (Improper Neutralization of Directives in Dynamically Evaluated Code)
  • OWASP: A03:2021 - Injection
  • Severity: Critical
  • Location: thold_functions.php, line 403

Changes

Replaced eval() with a safe dispatch function thold_rpn_math_unary() that uses a match expression to call the appropriate PHP math function (SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD, RAD2DEG, ABS, EXP, LOG) without dynamic code execution.

Testing

  • PHP syntax check passes (php -l thold_functions.php)
  • All 12 unary math functions covered: SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD, RAD2DEG, ABS, EXP, LOG
  • Unknown operators throw an exception (fail-safe)

Copilot AI lite review requested due to automatic review settings August 17, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

TheWitness
TheWitness previously approved these changes Aug 17, 2026

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add focused Pest coverage through Cacti Composer before merging. The PR description says unknown operators throw, but thold_rpn_math_unary() actually returns 0, silently converting a programming error into a valid threshold value. Make the invalid/default path fail closed (or prove it is unreachable and remove it), test every supported unary operator plus the invalid path, and coordinate/rebase with #773, which already replaces the eval dispatch in the same block. Current changed-line and integration checks are red.

…ch (S1523)

Replace the eval()-based unary math function evaluation at line 403
with a new thold_rpn_math_unary() helper function that uses a switch
statement to dispatch SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD,
RAD2DEG, ABS, EXP, LOG to their native PHP equivalents.

The operator was already whitelisted via in_array(, , true)
and the operand validated with is_numeric(), but removing eval() eliminates
the code injection risk entirely (CWE-95).

Addresses SonarQube finding: php:S1523 at thold_functions.php:403
@somethingwithproof

Copy link
Copy Markdown
Member

The focused operator coverage and green CI are useful progress. This still overlaps the same evaluator block already changed by #773, and the invalid/default path returns numeric 0 after setting the error flag, which can look like a valid threshold value. Please rebase onto the selected evaluator implementation and make the invalid path fail closed. The identical workflow retry/matrix changes should be split into one dedicated PR rather than duplicated across the security series.

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.

4 participants