Limit requests sent through session status iframe (#132) (#28864)

Closes #116

Signed-off-by: Jon Koops <jonkoops@gmail.com>
Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Stian Thorgersen 2024-04-18 14:02:37 +02:00 committed by GitHub
parent 2c069433f9
commit cbc4a8c305
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,6 +28,7 @@
}
let init;
let preventAdditionalRequests = false;
async function checkState(clientId, origin, sessionState) {
// Check if the browser has granted us access to 3rd-party storage (such as cookies).
@ -41,6 +42,13 @@
// If not initialized, verify this client is allowed access with a call to the server.
if (!init) {
// Prevent additional requests to the server to avoid potential DoS attacks.
if (preventAdditionalRequests) {
return "error";
} else {
preventAdditionalRequests = true;
}
const url = new URL(`${location.origin}${location.pathname}/init`);
url.searchParams.set("client_id", clientId);