FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(security): constrain config-driven code execution by XianBW · Pull Request #2340 · microsoft/qlib · GitHub

/ qlib Public

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

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

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

Conversation

XianBW (XianBW) commented Sep 2, 2026
edited
Loading

Copy link
Copy Markdown
Collaborator

Changes

  • Replace eval() in feature expressions and disk expression caching with a restricted AST interpreter. Preserve registered operators and safe parameter syntax, including bounded containers, argument unpacking, indexing/slicing, and scalar conditions.
  • Preserve quoted strings and necessary token boundaries during expression preprocessing and cache-key normalization.
  • Replace TRA model and performance-graph name evaluation with explicit mappings.
  • Require explicit, strictly boolean trusted=True for file-module imports, defaulting to refusal. Keep legacy module aliases for restoring trusted older file-based models.
  • Update affected TRA/LightGBM examples, add regression coverage, and connect migration guidance to documentation entry points and actionable errors.

Compatibility and migration

Package imports and standard Alpha158/Alpha360 expressions remain supported without opt-in. File-based components must explicitly authorize their imports:

task:
  model:
    class: MyModel
    module_path: custom_modules/model.py
    trusted: true
    kwargs: {}

Direct imports use get_module_by_module_path(path, trusted=True). Each nested file component needs its own consent; there is no global grant. Top-level trusted controls module loading, while kwargs.trusted remains a constructor argument.

Configurations and imported code must still be trusted. This is not a sandbox or directory-containment policy, and module-import consent does not enable unrestricted expressions or authorize artifact deserialization. Artifact-loading changes are handled separately in #2339.

See the configuration execution migration guide for supported syntax, custom extensions, and old-model recovery.

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

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.

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.

XianBW (XianBW) and others added 8 commits September 16, 2026 08:22
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match the repr-formatted module path in refusal messages and cover Windows, UNC, quoted, and newline-containing paths on every platform.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Log ExpressionSyntaxError with its field and traceback before re-raising, while preserving custom operator NameError and SyntaxError handling. Add five regression cases covering logging, exception identity, and failed cache entries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Capture parser logs directly on qlib.data without propagating to parent and root capture handlers. Restore logger state with monkeypatch and retain exact single-record, traceback, and exception-identity assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL