Skip to content

Safer script evaluation #6208

Open
Open

Description

@masenf

Summary

Implement safer script evaluation by running user-defined scripts in a well-defined, restrictive execution environment.

Proposed Changes

1. Restrictive evaluation environment

Evaluate scripts in a well-defined restrictive environment that only includes access to:

  • refs
  • Bundled libraries
  • state
  • queueEvents
  • addEvents

2. New script registration interface

Introduce a new interface for script execution: register a script snippet as a function that gets written out to utils/scripts.js. This provides a centralized, inspectable location for all registered script functions.

3. Python-side Var for the execution environment

Create a python-side Var that represents the execution environment, so that script snippets can reference names like refs or addEvents correctly and with proper type awareness.

Direction after #7794 (from the review)

Now that the frontend runtime lives in its own package (#7609, #7794), this is the next direction for that work: untangle script evaluation and find the best way to safely eval scripts.

  • A controlled environment that exposes a limited, well-defined API to scripts (the list above), with the ability to poke through additional libraries, like the mechanism dynamic components use for bundled libraries.
  • Expose that environment object to the Python side with a typed helper (item 3 above), so calling the APIs stays reliable as the actual JS code moves around.
  • Keep a "legacy" (dangerous) eval environment alongside it, based on the current state.js imports, so existing scripts keep working while they migrate.
  • Once both environments exist, start deconstructing state.js and really cleaning up the frontend code. Today event code is eval'd inside state.js and resolves names from its module scope, so moving functions out needs an integration test for that contract first (noted in Move the frontend javascript into its own package, reflex-frontend #7794).

Related: #7860 (direct eval in state.js stops minification of the shared chunk).

Cycle 166 acceptance

Show a Reflex app author can register and call a direct JavaScript snippet through the documented Python-facing interface. Verify the intended restricted API with benign integration tests and keep a regression test for the existing script path during migration.

Activity

  1. linear commented on Mar 24, 2026

    @linear
  2. added
    enhancement
    reflex-enterprise
    and removed on Mar 24, 2026
  3. added
    cloud
    build
    and removed
    cloud
    build
    on Mar 25, 2026
  4. removed
    cloud
    reflex-enterprise
    enhancement
    on Oct 20, 2026
  5. added
    roadmap
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

roadmap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions