Skip to content

feat(formula-safety): add opt-out to run unsafe formulas#1

Merged
sommaa merged 1 commit into
mainfrom
experimental
Jun 22, 2026
Merged

feat(formula-safety): add opt-out to run unsafe formulas#1
sommaa merged 1 commit into
mainfrom
experimental

Conversation

@sommaa

@sommaa sommaa commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a global, persisted (default-off) "Allow unsafe formulas" setting that disables the formula sandbox end-to-end, so trusted templates with non-whitelisted formulas can be imported, saved, and rendered. On a desktop-first, single-user, local app the user owns the machine and may knowingly trust their own templates.

Both enforcement layers honor a single runtime flag (otherwise a template would import but still fail to render):

  • Eval-timesafe_eval / safe_exec / assert_formula_safe / assert_no_escape in formula_safety.py
  • Template-timeassert_template_formulas_safe + the validate loop in templates.py

Changes

  • formula_safety: runtime flag (is_unsafe_allowed / set_unsafe_allowed) seeded from config; gate functions no-op and safe_eval/safe_exec run with real builtins when enabled
  • config: allow_unsafe_formulas seed (default false, env-overridable)
  • templates API: skip template-time formula checks when enabled
  • settings API (new): GET/PUT /api/v1/settings/security to toggle the flag at runtime
  • frontend: Security toggle in SettingsMenu, persisted in localStorage and mirrored to the backend (re-pushed on startup); "Enable unsafe formulas & retry" prompt in TemplateManager on unsafe-import rejection (covers the onboarding wizard too)
  • tests: backend coverage for the flag behavior and the settings endpoint

Security note

This is a deliberate opt-out: once enabled, a malicious template becomes arbitrary code execution. It defaults off, and both the Settings toggle and the import prompt spell out the risk.

Verification

  • 13 new backend tests + full suite (1031 passed; only pre-existing parquet/pyarrow failures, unrelated)
  • Frontend production typecheck: 0 new errors; uiSlice runtime tests pass
  • Driven end-to-end through the real :3000 → :8000 UI stack: unsafe template blocked (400) while off, accepted (200) after enable & retry, blocked again after reset

🤖 Generated with Claude Code

Adds a global, persisted (default-off) "Allow unsafe formulas" setting that
disables the formula sandbox end-to-end, so trusted templates with
non-whitelisted formulas can be imported, saved, and rendered.

- formula_safety: runtime flag (is_unsafe_allowed/set_unsafe_allowed) seeded
  from config; assert_formula_safe/assert_no_escape no-op and safe_eval/
  safe_exec run with real builtins when enabled
- config: allow_unsafe_formulas seed (default false)
- templates API: skip template-time formula checks when enabled
- settings API: GET/PUT /settings/security to toggle the flag at runtime
- frontend: Security toggle in SettingsMenu, persisted in localStorage and
  mirrored to the backend (re-pushed on startup); "Enable unsafe formulas &
  retry" prompt in TemplateManager on unsafe-import rejection
- tests: backend coverage for the flag and the settings endpoint
@sommaa
sommaa merged commit 8cccf9e into main Jun 22, 2026
2 of 4 checks passed
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