Skip to content

Bug CSRF session token is missing #39436

@joegom22

Description

@joegom22

Bug description

Bug summary

CSRF Session token is missing when calling the create dataset endpoint via the Python API after apparently successful login and csrf token retrieval. /api/v1/me/ returns 401 error but other endpoints such as copy dashboard or create role work just fine with the same requests.Session object.

Expected behavior

  • GET /api/v1/me/ should return the authenticated user information.
  • POST /api/v1/dataset/ should create the requested dataset successfully.

Actual behavior

  • GET /api/v1/me/ returns 401 {"message":"Not authorized"}.
  • POST /api/v1/dataset/ returns:
400, {"errors": [{"message": "400 Bad Request: The CSRF session token is missing.", "error_type": "GENERIC_BACKEND_ERROR", "level": "error", "extra": {"issue_codes": [{"code": 1011, "message": "Issue 1011 - Superset encountered an unexpected error."}]}}]}

Steps to reproduce

  1. Login via the login endpoint
  2. Update the access token header
  3. Obtain the csrf token
  4. Update the csrf token header
  5. Make a get request to /api/v1/me/
  6. Make a post request to /api/v1/dataset/

Python code / request example

r_session = requests.Session()
r_session.headers.update({
      'Accept': 'application/json',
     'Content-Type': 'application/json',
     'Referer': base_url
})
r = r_session.post(f"{base_url}/api/v1/security/login", json=login_data)
if r.status_code != 200:
      raise Exception(f"Failed to login: {r.status_code} {r.text}")
access_token = r.json()["access_token"]

r_session.headers.update({'Authorization': f"Bearer {access_token}"})
r = r_session.get(f"{base_url}/api/v1/security/csrf_token/")
if r.status_code != 200:
      raise Exception(f"Failed to get CSRF token: {r.status_code} {r.text}")
csrf_token = r.json()["result"]
r_session.headers.update({'X-CSRFToken': csrf_token})
r = r_session.get(base_url + f"/api/v1/me/", headers=r_session.headers)
print(f"Status: {r.status_code}")
print(f"Response: {r.text}")

r = r_session.post(
        base_url + f"/api/v1/dataset/"
        , json={
            "database": database,
            "table_name": table_name,
            "schema": schema
      }
)

if r.status_code == 201:
    logging.info(f"Dataset '{table_name}' has been created successfully in database '{database}' and schema '{schema}'")
    return r.json()["id"]
else:
    raise ValueError(f"Error creating dataset '{table_name}' in database '{database}' and schema '{schema}': {r.status_code}, {r.text}")

Tracebacks and returns

The Python tracebacks observed in the logs show:
10.31.232.26 - - [17/Apr/2026:11:25:57 +0000] "POST /api/v1/security/login HTTP/1.1" 200 487 URL "python-requests/2.33.1"
10.31.232.26 - - [17/Apr/2026:11:25:57 +0000] "GET /api/v1/security/csrf_token/ HTTP/1.1" 200 105 URL "python-requests/2.33.1"
10.31.232.26 - - [17/Apr/2026:11:25:57 +0000] "GET /api/v1/me/ HTTP/1.1" 401 29 URL "python-requests/2.33.1"

The POST request to the dataset seems to fail before it is even really made and so it does not show in the logs, however, the ValueError raised shows:
400, {"errors": [{"message": "400 Bad Request: The CSRF session token is missing.", "error_type": "GENERIC_BACKEND_ERROR", "level": "error", "extra": {"issue_codes": [{"code": 1011, "message": "Issue 1011 - Superset encountered an unexpected error."}]}}]}

Screenshots/recordings

No response

Superset version

6.0.0

Python version

3.11

Node version

I don't know

Browser

Chrome

Additional context

I have tried completely deleting the Public role to avoid possible known conflicts with this role and the Admin Role in api requests but it made no difference.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiRelated to the REST APIauthenticationRelated to authenticationvalidation:requiredA committer should validate the issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions