/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/auth/controller.js
27 строк
928 B
arthur791004
Add OAuth state parameter and validate redirects across all clients (#109414)
20 мар 2026, 11:04
Не верифицирован
20 мар 2026, 11:04
931419f
Код
Авторство
О чём код?
import store from 'store'; // Store token into local storage export function storeToken( context ) { // Validate the OAuth state parameter to prevent login CSRF / session fixation. const returnedState = context.hash?.state; const expectedState = sessionStorage.getItem( 'wpcom_oauth_state' ); sessionStorage.removeItem( 'wpcom_oauth_state' ); if ( ! returnedState || ! expectedState || returnedState !== expectedState ) { document.location.replace( '/' ); return; } if ( context.hash?.access_token ) { store.set( 'wpcom_token', context.hash.access_token ); } if ( context.hash?.expires_in ) { store.set( 'wpcom_token_expires_in', context.hash.expires_in ); } const { next = '/' } = context.query; // Validate that next is a safe relative path to prevent DOM XSS and open redirect. const isSafe = next.startsWith( '/' ) && ! next.startsWith( '//' ); document.location.replace( isSafe ? next : '/' ); }