fix(backend): constrain visualization target lambdas#1
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
Validate ROC target_lambda expressions before compiling them so visualization requests cannot execute arbitrary Python through function calls, imports, or attribute access. Encode visualization source values as Python string literals so non-custom visualizations cannot break out of generated notebook assignments. Signed-off-by: Cursor Agent <cursoragent@cursor.com>
db35689 to
8e51db4
Compare
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.
Description of your changes:
Severity: High
The visualization API forwards user-controlled visualization fields into a notebook that runs inside the visualization server pod. A caller who can create visualizations controlled
visualization.sourceand ROCarguments.target_lambda; the service interpolatedsourcedirectly into Python syntax and evaluatedtarget_lambdawitheval, allowing arbitrary Python execution through non-custom visualization requests.This change encodes
sourceas a Python string literal and compiles ROC target lambdas only after AST validation. The validator keeps simple row arithmetic/comparison expressions but rejects calls, imports, attributes, comprehensions, and other executable syntax.Primary location:
backend/src/apiserver/visualization/types/roc_curve.pyTesting:
PYTHONPATH=backend/src/apiserver/visualization python3 -m unittest backend/src/apiserver/visualization/test_safe_target_lambda.pyPYTHONPATH=backend/src/apiserver/visualization python3 -m py_compile backend/src/apiserver/visualization/server.py backend/src/apiserver/visualization/safe_target_lambda.py backend/src/apiserver/visualization/types/roc_curve.pyNot run: full visualization server unittest in this runner, because system Python is missing
tornado;pytestis also not installed.Checklist: