Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning to security context in check_auth doesn't work in Python #8133

Open
igorlukanin opened this issue Apr 11, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working python

Comments

@igorlukanin
Copy link
Member

Describe the bug
Apparently, assigning to security context works in check_auth in JavaScript but doesn't work in Python.

To Reproduce
Run the following cube.py snippet:

from cube import config
 
@config('query_rewrite')
def query_rewrite(query: dict, ctx: dict) -> dict:
  print("Query rewrite started")
  print(ctx)
  print("Query rewrite finished")
  return query

@config('check_auth')
def check_auth(ctx: dict, token: str) -> None:

  ctx['securityContext'] = {
    "sub": "1234567890",
    "iat": 1516239022,
    "user_id": 42
  }

  context = ctx['securityContext']

  print(context)
 
  if not context:
    raise Exception('Access denied')
  return ctx

Result:
Screenshot 2024-03-13 at 15 41 46

Expected behavior
Assigning to security context works in Python, 42 is printed as user_id inside the security context.

Version:
0.35.10

Additional context
We can fix this in a backwards-compatible way as follows:

  • Similarly to check_sql_auth, support returning security context from check_auth both in JavaScript and Python.
  • If nothing is returned, fall back to the current behavior.
@igorlukanin igorlukanin added bug Something isn't working python labels Apr 11, 2024
@ovr ovr self-assigned this Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python
Projects
None yet
Development

No branches or pull requests

2 participants