Skip to content

fix(security): constrain config-driven code execution - #2340

Open
XianBW (XianBW) wants to merge 12 commits into
mainfrom
security/constrain-config-execution
Open

fix(security): constrain config-driven code execution#2340
XianBW (XianBW) wants to merge 12 commits into
mainfrom
security/constrain-config-execution

Conversation

@XianBW

Copy link
Copy Markdown
Collaborator

Summary

  • replace Qlib feature-expression eval() with a restricted AST interpreter
  • replace TRA model and analysis graph eval() calls with explicit registries
  • disable file-based Python module imports by default and require configured trusted roots
  • update file-module examples to declare their trusted module roots

Security impact

Qlib expressions now accept only registered operators, constants, and supported expression operations. Python attributes, lambdas, comprehensions, imports, starred arguments, private operators, and arbitrary calls are rejected.

Configuration-driven .py modules remain available as an intentional extension mechanism, but only when their resolved path is contained by a caller-provided or Qlib-configured trusted_module_roots directory. Symlink and parent-directory escapes are rejected after path resolution.

Compatibility

Package module paths such as qlib.contrib.model.pytorch_tra are unchanged. Configurations intentionally loading local Python files must declare trusted roots, for example:

qlib_init:
  trusted_module_roots: [.]

The affected LightGBM multi-frequency and TRA examples have been updated accordingly.

Validation

  • py_compile for changed Python files
  • git diff --check
  • validated all eight modified YAML configurations
  • verified common expressions including Ref, Mean, If, comparisons, and boolean composition
  • verified malicious Python execution expressions are rejected
  • verified file imports are denied by default, accepted within a trusted root, and rejected outside it

Full project pytest is delegated to CI because the local base environment does not contain Qlib's complete optional dependency set.

@XianBW XianBW (XianBW) changed the title security: constrain config-driven code execution fix(security): constrain config-driven code execution Sep 2, 2026
@XianBW

Copy link
Copy Markdown
Collaborator Author

Local verification update:

  • 18 security regression tests passed
  • security tests plus handler serialization and full train/backtest pipeline: 22 passed
  • repository-wide Black, Flake8, and Pylint passed
  • all eight modified example YAML files parsed successfully
  • removed the optional Plotly import from the registry regression test so test collection is independent of the analysis extra

The branch also contains minimal CI compatibility fixes for current Node/commitlint, Plotly, MLflow, and Windows/Python 3.8 OSQP behavior.

@XianBW

Copy link
Copy Markdown
Collaborator Author

Final verification: all 76 GitHub checks pass on commit ee6b4518/latest branch state, including title, CLA, pip compatibility, source builds, notebook execution, full pytest, and slow pytest matrices.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant