[Embedding Dashboard] GLOBAL_ASYNC_QUERIES fails with 401 InvalidSubjectError for guest/embedded users

Aperta Adatta ai principianti
#46,567 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia da superset/async_events/async_query_manager.py: l'hook after_request in register_request_handlers() costruisce il JWT del canale con sub impostato a None quando get_user_id() è None, e parse_channel_id_from_request() lo decodifica. Per riprodurre, invia una richiesta POST /api/v1/chart/data non autenticata con GLOBAL_ASYNC_QUERIES abilitato e verifica se compare un 401. È completato quando le richieste ospite ricevono un token valido senza sub nullo e rispondono senza 401, mentre il comportamento esistente per le richieste autenticate resta invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

#bug
Bug description

When EMBEDDED_SUPERSET and GLOBAL_ASYNC_QUERIES are both enabled, embedded dashboards fail to load chart data and native filters for guest users. Every POST /api/v1/chart/data request returns HTTP 401 with InvalidSubjectError: Subject must be a string.

Root Cause
In superset/async_events/async_query_manager.py:
In AsyncQueryManager.register_request_handlers() (after_request), sub is set to None when get_user_id() is None (which is always the case for embedded GuestUser / unauthenticated users):

sub = str(user_id) if user_id else None
token = jwt.encode(
    {"channel": async_channel_id, "sub": sub},
    self._jwt_secret,
    algorithm="HS256",
)
  • Encoding "sub": None produces "sub": null in the JWT payload.
  • In AsyncQueryManager.parse_channel_id_from_request(), jwt.decode(...) raises jwt.exceptions.InvalidSubjectError: Subject must be a string (PyJWT enforces sub to be a string when present, per RFC 7519).
  • AsyncQueryTokenException is raised, causing ChartDataRestApi to return HTTP 401.

How to Reproduce

  1. Enable both EMBEDDED_SUPERSET = True and GLOBAL_ASYNC_QUERIES = True in superset_config.py.
  2. Embed a dashboard using @superset-ui/embedded-sdk in an external app (without an active Superset user login session in the browser).
  3. Load the embedded dashboard.

Actual Behavior

  • POST /api/v1/chart/data returns 401.
  • Charts display Data error, native filters display Network error, and the embedded UI shows: "This session has encountered an interruption, and some controls may not work as intended...".
  • Server log:
WARNING:superset.async_events.async_query_manager:Parse jwt failed
...
jwt.exceptions.InvalidSubjectError: Subject must be a string

Expected Behavior

Guest/embedded users should receive a valid async channel JWT and load chart data and native filters without 401 errors.

Suggested Fix

Omit "sub" from the JWT payload when user_id is None:

python

payload: dict[str, Any] = {"channel": async_channel_id}
if user_id is not None:
    payload["sub"] = str(user_id)
token = jwt.encode(payload, self._jwt_secret, algorithm="HS256")

(Optionally also pass options={"verify_sub": False} in jwt.decode(...) for backwards compatibility with existing cookies.)

Screenshots/recordings

No response

Superset version

6.1.0

Python version

3.12

Node version

18 or greater

Browser

Chrome

Additional context

No response

Checklist
  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Lingua principale
Python
Stelle
75.6k
Fork
18.6k
Merge medio
4g 2h
PR unite (30g)
469

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/superset

Tutte le issue di apache/superset

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.