Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Fix security concerns#515

Merged
liqul merged 2 commits intomainfrom
liqun/icm31000000533231
Jan 27, 2026
Merged

Fix security concerns#515
liqul merged 2 commits intomainfrom
liqun/icm31000000533231

Conversation

@liqul
Copy link
Collaborator

@liqul liqul commented Jan 27, 2026

Summary of Security Improvements

1. Strengthened AST Validation (code_verification.py)

  • Added DANGEROUS_BUILTINS constant listing security-sensitive functions/attributes
  • Enhanced visit_Call() to detect:
  • Subscript-based function calls (e.g., obj"method")
  • Chained calls for dynamic resolution (e.g., getattr(obj, 'method')())
  • Unrecognized call patterns
  • Dangerous builtin functions
  • Added visit_Subscript() to detect dictionary-based dunder access (e.g., obj["class"])
  • Added visit_Attribute() to detect direct dangerous attribute access (e.g., obj.class)

2. Updated Default Blocklist (code_interpreter.py)

Added these dangerous functions to the default blocked list:

  • getattr, setattr, delattr
  • vars, globals, locals
  • getattribute, setattr, delattr

3. Code Verification Enabled by Default for Local Mode (code_interpreter.py)

  • Code verification is now automatically enabled when running in local mode
  • A warning is logged to inform users about the security implications
  • Users can still explicitly disable it, but this is discouraged

4. Security Guidance in Code Generator Prompt (code_generator_prompt.yaml & code_generator.py)

Added explicit security guidelines that instruct the LLM to:

  • Never use dangerous functions like eval(), exec(), getattr(), etc.
  • Never access dunder attributes
  • Never execute shell commands unless required
  • Refuse requests that attempt to bypass security
  • The security requirements are included in the prompt when code verification is enabled

5. New Unit Tests (test_code_verification.py)

Added comprehensive tests for:

  • Dynamic attribute access (getattr, setattr, delattr)
  • globals() and locals() blocking
  • Dunder attribute access (class, bases)
  • Subscript-based dunder access
  • Subscript-based function call bypass patterns
  • vars() function blocking

@liqul liqul requested a review from Jack-Q January 27, 2026 03:44
@liqul liqul enabled auto-merge January 27, 2026 03:51
@liqul liqul merged commit 0c5747a into main Jan 27, 2026
2 checks passed
liqul added a commit to liqul/TaskWeaverFork that referenced this pull request Feb 3, 2026
# Summary of Security Improvements

## 1. Strengthened AST Validation (code_verification.py)
- Added DANGEROUS_BUILTINS constant listing security-sensitive
functions/attributes
- Enhanced visit_Call() to detect:
- Subscript-based function calls (e.g., obj["method"]())
- Chained calls for dynamic resolution (e.g., getattr(obj, 'method')())
- Unrecognized call patterns
- Dangerous builtin functions
- Added visit_Subscript() to detect dictionary-based dunder access
(e.g., obj["__class__"])
- Added visit_Attribute() to detect direct dangerous attribute access
(e.g., obj.__class__)

## 2. Updated Default Blocklist (code_interpreter.py)
Added these dangerous functions to the default blocked list:

- getattr, setattr, delattr
- vars, globals, locals
- __getattribute__, __setattr__, __delattr__

## 3. Code Verification Enabled by Default for Local Mode
(code_interpreter.py)
- Code verification is now automatically enabled when running in local
mode
- A warning is logged to inform users about the security implications
- Users can still explicitly disable it, but this is discouraged

## 4. Security Guidance in Code Generator Prompt
(code_generator_prompt.yaml & code_generator.py)
Added explicit security guidelines that instruct the LLM to:

- Never use dangerous functions like eval(), exec(), getattr(), etc.
- Never access dunder attributes
- Never execute shell commands unless required
- Refuse requests that attempt to bypass security
- The security requirements are included in the prompt when code
verification is enabled

## 5. New Unit Tests (test_code_verification.py)
Added comprehensive tests for:

- Dynamic attribute access (getattr, setattr, delattr)
- globals() and locals() blocking
- Dunder attribute access (__class__, __bases__)
- Subscript-based dunder access
- Subscript-based function call bypass patterns
- vars() function blocking
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants