Skip to content

Conversation

@lresende
Copy link
Member

No description provided.

@lresende lresende requested a review from kevin-bates July 25, 2025 18:31
@lresende lresende requested a review from Zsailer August 6, 2025 20:54
@Zsailer
Copy link
Member

Zsailer commented Aug 8, 2025

This looks great, @lresende!

I think I found a small security gap that needs addressing before merge.

The current regex pattern [a-zA-Z_][a-zA-Z0-9_]* allows variables starting with underscores, which means {{ __class__ }} would be accepted and could potentially enable Python magic method attacks.

Imagine someone doing this:

  # Malicious KERNEL_POD_NAME that could be accepted by current regex:
  KERNEL_POD_NAME = "{{
  kernel_id.__class__.__mro__[1].__subclasses__()[104].__init__.__globals__['sys'].exit }}"

If __class__ were somehow in the variables dict, this could expose:

  • Object introspection capabilities
  • Access to the class hierarchy
  • Potential stepping stone for more complex attacks

I think the regex should block anything with a leading underscore,

pattern = r'\{\{\s*([a-zA-Z][a-zA-Z0-9_]*)\s*\}\}'  # No leading underscore

I think if we can fix this and add a test case, we should be good to go here.

@lresende
Copy link
Member Author

lresende commented Aug 8, 2025

Thank you @Zsailer , good catch. I have updated it:

  1. Updated the regex pattern in enterprise_gateway/services/processproxies/k8s.py:226 to prevent variables starting with underscore:
    - Changed from: r'{{\s*([a-zA-Z_][a-zA-Z0-9_])\s}}'
    - To: r'{{\s*([a-zA-Z][a-zA-Z0-9_])\s}}'
  2. Enhanced the test case in enterprise_gateway/tests/test_process_proxy.py to verify that underscore-prefixed variables (like class, dict, globals) are properly blocked and treated as invalid template syntax.

@lresende lresende merged commit 1e6b2f3 into jupyter-server:main Aug 9, 2025
13 checks passed
@lresende lresende deleted the security-ssti branch August 9, 2025 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants