Skip to content

[Codex] fix(logic): harden formula eval against sandbox escape#527

Open
Micsi wants to merge 2 commits into
abeggled:mainfrom
Micsi:codex/propose-fix-for-datapoint-formula-vulnerability-pf7jwp
Open

[Codex] fix(logic): harden formula eval against sandbox escape#527
Micsi wants to merge 2 commits into
abeggled:mainfrom
Micsi:codex/propose-fix-for-datapoint-formula-vulnerability-pf7jwp

Conversation

@Micsi
Copy link
Copy Markdown
Collaborator

@Micsi Micsi commented May 20, 2026

Source PR

Motivation

  • value_formula strings from user-editable datapoint nodes were evaluated via GraphExecutor._safe_eval and could be abused to escape the Python sandbox and execute arbitrary code via object introspection.
  • The previous mitigation only removed __builtins__, which is insufficient to prevent attribute traversal and other Python constructs from reaching import or OS primitives.
  • This change hardens formula evaluation to prevent RCE while preserving existing math/formatting functionality.

Description

  • Added GraphExecutor._validate_formula_ast which inspects the parsed AST and rejects disallowed node types and constructs before evaluation.
  • Called the new _validate_formula_ast from GraphExecutor._safe_eval to enforce an allowlist of safe AST nodes and permitted names.
  • Restricted function calls to direct name calls present in the allowlist and reject attribute access, comprehensions, and indirect calls.
  • Updated unit tests in tests/unit/test_executor.py to assert that attribute-based sandbox escape payloads are blocked (replacing the previous attribute-access expectation).

Testing

  • Ran the modified unit tests with pytest -q tests/unit/test_executor.py, which completed successfully with 193 passed and no failures.
  • The changes are limited to obs/logic/executor.py and tests/unit/test_executor.py and preserve existing executor behavior for allowed math expressions.

Codex Task

@Micsi Micsi added the Security Security-related changes label May 20, 2026
@Micsi Micsi requested a review from abeggled May 20, 2026 11:14
@Micsi Micsi self-assigned this May 20, 2026
@Micsi
Copy link
Copy Markdown
Collaborator Author

Micsi commented May 20, 2026

Ergänzung zur Nachvollziehbarkeit der letzten Änderung:

Zusätzlich zum bestehenden Security-Fix wurde ein gezielter Unit-Test ergänzt, um einen bisher nicht explizit getesteten Guard-Branch abzudecken.

Was wurde zusätzlich gemacht?

  • In tests/unit/test_executor.py wurde test_indirect_function_call_blocked ergänzt.
  • Der Test prüft explizit, dass indirekte Funktionsaufrufe wie ([abs][0])(1) in _safe_eval geblockt werden.
  • Damit ist der Schutzpfad Only direct function calls are allowed jetzt direkt durch einen Test abgesichert.

Warum war das wichtig?

  • Der ursprüngliche PR hat die AST-Validierung korrekt gehärtet.
  • Es fehlte aber noch ein dedizierter Test für genau diesen indirekten Call-Pfad.
  • Die funktionale Änderung ist klein, aber erhöht die Sicherheit der Testaussage deutlich.

Verifikation

  • pytest -q tests/unit/test_executor.py lief nach der Ergänzung grün (194 passed).

Einordnung

  • Keine zusätzliche Produktlogik geändert, nur Testabdeckung erweitert.
  • Die separat beobachtete Flakiness im Integrationstest test_chart_mehrere_werte betrifft einen anderen Bereich (History/Chart) und ist nicht Teil dieses Security-Scopes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Security Security-related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant