Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
This PR addresses #30900, which reports a "400 Bad Request: The CSRF session token is missing" error during cache warmup. The issue was due to missing header updates with the CSRF token and cookie (expecting session='session_cookie'). This PR ensures the token is correctly fetched and included in headers during the warmup process, resolving the error.
Fixes #30900
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Success:
TESTING INSTRUCTIONS
Since we are now explicitly fetching the CSRF token, we can enable
WTF_CSRF_ENABLED = True
or safely removeWTF_CSRF_EXEMPT_LIST
for any cache warmup-related endpoints. This ensures that all requests, including those for cache warmup, are properly validated with CSRF protection, thereby enhancing application security.If CSRF protection is disabled or the endpoint is exempted, no CSRF checks will be performed. However, the
ChartRestApi.warm_up_cache
endpoint still requires a session cookie (session=session_cookie
) to determine the user's context and permissions. Without this, the request will fail with a401 Unauthorized error
.This PR ensures the session cookie is correctly updated in the request headers under the Cookie field, enabling the user context to be accurately resolved for authorization.
ADDITIONAL INFORMATION