Skip to content

fix(auth-v2): CSRF redirect logic #96455

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/sentry/templates/sentry/403-csrf-failure.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2>{% trans "CSRF Validation Failed" %}</h2>
const forceRefreshPage = () => {
setTimeout(() => {
// NOTE: window.location.reload(true) does not work on Chrome
window.location.replace(window.location.href);
window.location.replace('/auth/login/');
}, 500);
};

Expand Down Expand Up @@ -94,7 +94,7 @@ <h2>{% trans "CSRF Validation Failed" %}</h2>
*/
const rotateCsrf = async (isAutoRotate = false) => {
button.disabled = true;
button.textContent = '{% trans "Rotating..." %}';
button.textContent = 'Rotating...';
status.textContent = '';

try {
Expand All @@ -104,15 +104,15 @@ <h2>{% trans "CSRF Validation Failed" %}</h2>
throw new Error();
}

status.textContent = '{% trans "Token rotated! Refreshing the page in 1 sec..." %}';
status.textContent = 'Token rotated! Refreshing the page in 1 sec...';
status.style.color = 'green';
forceRefreshPage();
} catch (error) {
status.textContent = '{% trans "Failed to rotate token." %}';
status.textContent = 'Failed to rotate token.';
status.style.color = 'red';
} finally {
button.disabled = false;
button.textContent = '{% trans "Rotate CSRF Token" %}';
button.textContent = 'Rotate CSRF Token';
}
};

Expand All @@ -137,7 +137,7 @@ <h2>{% trans "CSRF Validation Failed" %}</h2>
localStorage.setItem('lastCsrfError', new Date().toISOString());

button.disabled = true;
status.textContent = '{% trans "Automatically rotating tokens..." %}';
status.textContent = 'Automatically rotating tokens...';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Token Rotation Message and I18n Issues

This commit introduces two bugs:

  1. The "Token rotated! Refreshing the page in 1 sec..." message is misleading, as the page now redirects to /auth/login/ instead of refreshing the current page.
  2. Internationalization support was removed from several user-facing JavaScript strings by replacing Django translation tags ({% trans %}) with hardcoded English text. This breaks multi-language support for messages such as "Rotating...", "Token rotated! Refreshing the page in 1 sec...", "Failed to rotate token.", "Rotate CSRF Token", and "Automatically rotating tokens...", causing them to always display in English and creating inconsistent internationalization with the rest of the template.
Locations (1)

Fix in CursorFix in Web

status.style.color = 'green';
setTimeout(() => rotateCsrf(true), 1500);
}
Expand Down
Loading