Skip to content

Commit

Permalink
Fixed infinite loop in client-side reCAPTCHA verification mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Feb 2, 2025
1 parent c0c46f3 commit 331ec91
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion assets/scripts/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function setupRecaptcha()
{
if ( typeof window.grecaptcha !== "undefined" )
{
fetch( "", { method: "POST" } );
window.proxyFetch( "", { method: "POST" } );
clearInterval( timer );
}
}, 1000 );
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ setInterval( () =>
export async function sendRemoteAction( token: string, route: string, action: string, value = "" )
{
// On réalise d'abord la requête AJAX.
const response = await fetch( route, {
const response = await window.proxyFetch( route, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down
11 changes: 6 additions & 5 deletions assets/scripts/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { addQueuedNotification } from "./functions";
// Déclaration du contexte global du navigateur.
declare global {
interface Window {
// Méthode fetch avec prise en charge de reCAPTCHA.
proxyFetch: typeof fetch;

// Déclaration des traductions injectées par Twig.
edit_port: string;
edit_remove: string;
Expand Down Expand Up @@ -114,9 +117,7 @@ $( "footer" ).on( "click", "a[href = \"#\"]", ( event ) =>
//
if ( process.env.RECAPTCHA_ENABLED === "true" )
{
const oldFetch = window.fetch;

window.fetch = async ( url, options ) =>
window.proxyFetch = async ( url, options ) =>
{
// On vérifie d'abord si la requête est une requête issue
// d'un formulaire quelconque.
Expand Down Expand Up @@ -153,7 +154,7 @@ if ( process.env.RECAPTCHA_ENABLED === "true" )
}

// On retourne enfin la requête originale.
return oldFetch( url, options );
return fetch( url, options );
};

$( "form[method = POST]" ).on( "submit", ( event ) =>
Expand Down Expand Up @@ -240,7 +241,7 @@ contact.on( "submit", "form", async ( event ) =>
contact.find( "[type = reset]" ).prop( "disabled", true );

// On réalise alors la requête AJAX.
const response = await fetch( contact.data( "route" ), {
const response = await window.proxyFetch( contact.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down
4 changes: 2 additions & 2 deletions assets/scripts/pages/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ commands.on( "click", "[data-action = add]", async ( event ) =>
element.prop( "disabled", true );

// On réalise ensuite la requête AJAX.
const response = await fetch( element.data( "route" ), {
const response = await window.proxyFetch( element.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -133,7 +133,7 @@ commands.on( "click", "[data-action = remove]", async ( event ) =>

// On réalise ensuite la requête AJAX.
const target = $( event.target );
const response = await fetch( target.data( "route" ), {
const response = await window.proxyFetch( target.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down
4 changes: 2 additions & 2 deletions assets/scripts/pages/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $( "form" ).on( "submit", async ( event ) =>
storage.find( "[type = submit]" ).prop( "disabled", true );

// On réalise ensuite la requête AJAX.
const response = await fetch( storage.data( "route" ), {
const response = await window.proxyFetch( storage.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -93,7 +93,7 @@ $( "[data-type]" ).on( "click", async ( event ) =>
// On réalise ensuite la requête AJAX.
const target = $( event.target );
const element = target.is( "i" ) ? target.parent() : target;
const response = await fetch( parameters.data( "route" ), {
const response = await window.proxyFetch( parameters.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/pages/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let timer: NodeJS.Timeout | undefined;
async function retrieveRemoteLogs()
{
// On réalise d'abord la requête AJAX.
const response = await fetch( terminal.data( "route" ) );
const response = await window.proxyFetch( terminal.data( "route" ) );

// On vérifie ensuite si la requête a été effectuée avec succès.
if ( response.ok )
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/pages/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ let timer: NodeJS.Timeout | undefined;
async function retrieveRemoteData()
{
// On réalise d'abord la requête AJAX.
const response = await fetch( servers.data( "route" ) );
const response = await window.proxyFetch( servers.data( "route" ) );

// On vérifie ensuite si la requête a été effectuée avec succès.
if ( response.ok )
Expand Down
6 changes: 3 additions & 3 deletions assets/scripts/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ register.on( "submit", "form", async ( event ) =>
// Dans le cas contraire, on réalise alors une requête AJAX
// pour envoyer les informations au serveur.
const parent = register.parent();
const response = await fetch( parent.data( "route" ), {
const response = await window.proxyFetch( parent.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -187,7 +187,7 @@ login.on( "click", "[type = submit]", async ( event ) =>
login.find( "[type = reset]" ).prop( "disabled", true );

// On réalise ensuite la requête AJAX.
const response = await fetch( login.data( "route" ), {
const response = await window.proxyFetch( login.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -291,7 +291,7 @@ links.last().on( "click", async ( event ) =>

// On réalise ensuite la requête AJAX.
const parent = $( event.target ).parent();
const response = await fetch( parent.data( "route" ), {
const response = await window.proxyFetch( parent.data( "route" ), {
method: "PUT",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down
4 changes: 2 additions & 2 deletions assets/scripts/pages/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $( "form" ).on( "submit", async ( event ) =>
tasks.find( "[type = submit]" ).prop( "disabled", true );

// On réalise ensuite la requête AJAX.
const response = await fetch( tasks.data( "add-route" ), {
const response = await window.proxyFetch( tasks.data( "add-route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -71,7 +71,7 @@ $( "tbody tr:not([class = finished])" ).on( "click", async ( event ) =>
{
// On réalise ensuite la requête AJAX.
const target = $( event.target ).parent();
const response = await fetch( tasks.data( "remove-route" ), {
const response = await window.proxyFetch( tasks.data( "remove-route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down
6 changes: 3 additions & 3 deletions assets/scripts/pages/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ account.on( "click", "[data-action]", async ( event ) =>
account.find( "[type = submit]" ).prop( "disabled", true );

// On réalise alors la requête AJAX.
const response = await fetch( target.data( "route" ), {
const response = await window.proxyFetch( target.data( "route" ), {
method: action === "update" ? "PUT" : "DELETE",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -92,7 +92,7 @@ actions.on( "click", "[type = submit]", async ( event ) =>

// On réalise ensuite la requête AJAX.
const target = $( event.target );
const response = await fetch( target.data( "route" ), {
const response = await window.proxyFetch( target.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -151,7 +151,7 @@ submit.on( "click", async ( event ) =>
// On réalise ensuite la requête AJAX.
const target = $( event.target );
const form = target.parent();
const response = await fetch( register.data( "route" ), {
const response = await window.proxyFetch( register.data( "route" ), {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
Expand Down

0 comments on commit 331ec91

Please sign in to comment.