Skip to content

šŸ›”ļø Sentinel: [MEDIUM] Block function reflection attributes in ASTScanner - #290

Merged
traoreera merged 1 commit into
mainfrom
fix/security-forbidden-attributes-reflection-9968355375119502117
Oct 6, 2026
Merged

traoreera merged 1 commit into
mainfrom
fix/security-forbidden-attributes-reflection-9968355375119502117

Conversation

@traoreera

@traoreera traoreera commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

Added function reflection/introspection attributes (__closure__, __defaults__, __kwdefaults__, __func__, __self__, __module__) to FORBIDDEN_ATTRIBUTES in xcore/kernel/security/section.py. This prevents untrusted plugins from inspecting function closures, default values, or bound method targets during AST scanning.

Changes

  1. Core Kernel Security:
    • Updated FORBIDDEN_ATTRIBUTES in xcore/kernel/security/section.py.
  2. Tests:
    • Added test_ast_scanner_blocks_reflection_forbidden_attributes in tests/unit/security/test_sentinel_fixes.py.

PR created automatically by Jules for task 9968355375119502117 started by @traoreera

Summary by Sourcery

Block function reflection attributes during AST scanning to strengthen plugin security.

Bug Fixes:

  • Prevent AST-scanned untrusted plugins from accessing function reflection attributes that expose closures, defaults, bound targets, and module metadata.

Tests:

  • Add coverage verifying the AST scanner rejects the newly forbidden function reflection attributes.

Enhance FORBIDDEN_ATTRIBUTES in xcore/kernel/security/section.py to block function reflection/introspection attributes (__closure__, __defaults__, __kwdefaults__, __func__, __self__, __module__) during AST scanning to prevent sandbox bypasses.
@google-labs-jules

Copy link
Copy Markdown
Contributor

šŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a šŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai

sourcery-ai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The PR hardens ASTScanner against function introspection by adding closure, default-value, bound-method, and module reflection attributes to FORBIDDEN_ATTRIBUTES, with a regression test confirming all six accesses are rejected and reported.

Flow diagram for ASTScanner blocking function reflection

flowchart LR
    Plugin[Untrusted plugin code] --> ASTScanner[ASTScanner]
    ASTScanner --> Forbidden[FORBIDDEN_ATTRIBUTES]
    Forbidden --> Reject[Reject attribute access]
    Reject --> Report[Report security violation]
Loading

File-Level Changes

Change Details Files
Expands AST-level attribute restrictions to prevent function and bound-method introspection by untrusted plugins.
  • Adds six reflection attributes to the forbidden-attribute allowlist.
  • Preserves existing scanner behavior while causing each prohibited access to be reported.
xcore/kernel/security/section.py
Adds regression coverage verifying all newly prohibited reflection attributes are detected.
  • Creates a temporary plugin source file accessing each restricted attribute.
  • Asserts scanning fails and reports every expected attribute violation.
tests/unit/security/test_sentinel_fixes.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="xcore/kernel/security/section.py" line_range="31-36" />
<code_context>
     "__globals__",
     "__subclasses__",
     "__code__",
+    "__closure__",
+    "__defaults__",
+    "__kwdefaults__",
+    "__func__",
+    "__self__",
+    "__module__",
     "__mro__",
     "__builtins__",
</code_context>
<issue_to_address>
**String helpers bypass attribute blocking**

When a plugin passes a newly forbidden reflection name to an `attrgetter` helper, `ASTScanner` checks only `ast.Attribute` names, so it misses names passed as strings to `operator.attrgetter` or `functools.attrgetter`. The scan passes and the plugin can still inspect function internals.

Have `ASTScanner` reject newly forbidden names passed to `attrgetter` helpers.
</issue_to_address>

### Comment 2
<location path="xcore/kernel/security/section.py" line_range="31-36" />
<code_context>
     "__globals__",
     "__subclasses__",
     "__code__",
+    "__closure__",
+    "__defaults__",
+    "__kwdefaults__",
+    "__func__",
+    "__self__",
+    "__module__",
     "__mro__",
     "__builtins__",
</code_context>
<issue_to_address>
**Ephemeral plugins run after failed scans**

When an EPHEMERAL-mode plugin uses a newly forbidden attribute, `EphemeralActivator.activate` logs the scan errors and continues to `EphemeralHandler.start`, whose warm pool loads the plugin through the in-process `LifecycleManager`. The forbidden reflection access therefore runs in the kernel process.

Make `EphemeralActivator.activate` stop activation when the scan fails.
</issue_to_address>

### Comment 3
<location path="xcore/kernel/security/section.py" line_range="31-36" />
<code_context>
     "__globals__",
     "__subclasses__",
     "__code__",
+    "__closure__",
+    "__defaults__",
+    "__kwdefaults__",
+    "__func__",
+    "__self__",
+    "__module__",
     "__mro__",
     "__builtins__",
</code_context>
<issue_to_address>
**Security guide omits blocked attributes**

The sandboxed-plugin guide lists `__subclasses__`, `__mro__`, `__globals__`, and `__builtins__` as blocked attributes but omits the six added here, so plugin authors relying on the guide do not learn that these accesses are rejected during scanning.

Update the sandboxed-plugin guide’s blocked-attribute list to include the six new entries.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and this adds a security policy decision that rejects any scanned code using these function attributes; if the denylist is wrong or incomplete, the behavior is wrong for every affected scan from the moment it ships, and an ordinary revert does not recover any denied deployment decisions already made.

Blocking findings: xcore/kernel/security/section.py:36, xcore/kernel/security/section.py:36


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +31 to +36
"__closure__",
"__defaults__",
"__kwdefaults__",
"__func__",
"__self__",
"__module__",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · String helpers bypass attribute blocking

When a plugin passes a newly forbidden reflection name to an attrgetter helper, ASTScanner checks only ast.Attribute names, so it misses names passed as strings to operator.attrgetter or functools.attrgetter. The scan passes and the plugin can still inspect function internals.

Have ASTScanner reject newly forbidden names passed to attrgetter helpers.

Prompt for AI agents
In `xcore/kernel/security/section.py` at lines 31-36:

**String helpers bypass attribute blocking**

When a plugin passes a newly forbidden reflection name to an `attrgetter` helper, `ASTScanner` checks only `ast.Attribute` names, so it misses names passed as strings to `operator.attrgetter` or `functools.attrgetter`. The scan passes and the plugin can still inspect function internals.

Have `ASTScanner` reject newly forbidden names passed to `attrgetter` helpers.

Comment on lines +31 to +36
"__closure__",
"__defaults__",
"__kwdefaults__",
"__func__",
"__self__",
"__module__",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Ephemeral plugins run after failed scans

When an EPHEMERAL-mode plugin uses a newly forbidden attribute, EphemeralActivator.activate logs the scan errors and continues to EphemeralHandler.start, whose warm pool loads the plugin through the in-process LifecycleManager. The forbidden reflection access therefore runs in the kernel process.

Make EphemeralActivator.activate stop activation when the scan fails.

Prompt for AI agents
In `xcore/kernel/security/section.py` at lines 31-36:

**Ephemeral plugins run after failed scans**

When an EPHEMERAL-mode plugin uses a newly forbidden attribute, `EphemeralActivator.activate` logs the scan errors and continues to `EphemeralHandler.start`, whose warm pool loads the plugin through the in-process `LifecycleManager`. The forbidden reflection access therefore runs in the kernel process.

Make `EphemeralActivator.activate` stop activation when the scan fails.

Comment on lines +31 to +36
"__closure__",
"__defaults__",
"__kwdefaults__",
"__func__",
"__self__",
"__module__",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Low · Security guide omits blocked attributes

The sandboxed-plugin guide lists __subclasses__, __mro__, __globals__, and __builtins__ as blocked attributes but omits the six added here, so plugin authors relying on the guide do not learn that these accesses are rejected during scanning.

Update the sandboxed-plugin guide’s blocked-attribute list to include the six new entries.

Prompt for AI agents
In `xcore/kernel/security/section.py` at lines 31-36:

**Security guide omits blocked attributes**

The sandboxed-plugin guide lists `__subclasses__`, `__mro__`, `__globals__`, and `__builtins__` as blocked attributes but omits the six added here, so plugin authors relying on the guide do not learn that these accesses are rejected during scanning.

Update the sandboxed-plugin guide’s blocked-attribute list to include the six new entries.

@traoreera
traoreera merged commit 038132e into main Oct 6, 2026
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant