feat(formula-safety): add opt-out to run unsafe formulas#1
Merged
Conversation
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
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.
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):
safe_eval/safe_exec/assert_formula_safe/assert_no_escapeinformula_safety.pyassert_template_formulas_safe+ the validate loop intemplates.pyChanges
is_unsafe_allowed/set_unsafe_allowed) seeded from config; gate functions no-op andsafe_eval/safe_execrun with real builtins when enabledallow_unsafe_formulasseed (defaultfalse, env-overridable)GET/PUT /api/v1/settings/securityto toggle the flag at runtimeSettingsMenu, persisted inlocalStorageand mirrored to the backend (re-pushed on startup); "Enable unsafe formulas & retry" prompt inTemplateManageron unsafe-import rejection (covers the onboarding wizard too)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
uiSliceruntime tests pass:3000 → :8000UI stack: unsafe template blocked (400) while off, accepted (200) after enable & retry, blocked again after reset🤖 Generated with Claude Code