From c56d4cea9eb38bb12e3ae54053d7f54978109b6f Mon Sep 17 00:00:00 2001
From: Francois Aube
Date: Sat, 10 Aug 2024 03:00:52 -0400
Subject: [PATCH] fix(recaptcha): remove execute/assessment from homepage load.
(#3759)
* move demo.js to a new name
* Remove execute/assessment from home page.
* Revert unintended change to copyright stanzas.
* Update demo.js file with home page changes.
---------
Co-authored-by: Sita Lakshmi Sangameswaran
Co-authored-by: Adam Ross
Co-authored-by: Tony Pujals
---
.../demosite/app/config.properties | 1 -
.../demosite/app/controllers/controller.js | 45 -------------------
recaptcha_enterprise/demosite/app/routes.js | 2 -
.../{demo-6df0841a.js => demo-2af4c10e.js} | 15 +++----
.../demosite/app/templates/comment.html | 2 +-
.../demosite/app/templates/home.html | 37 +--------------
.../demosite/app/templates/login.html | 2 +-
.../demosite/app/templates/signup.html | 2 +-
.../demosite/app/templates/store.html | 2 +-
9 files changed, 10 insertions(+), 98 deletions(-)
rename recaptcha_enterprise/demosite/app/static/{demo-6df0841a.js => demo-2af4c10e.js} (99%)
diff --git a/recaptcha_enterprise/demosite/app/config.properties b/recaptcha_enterprise/demosite/app/config.properties
index 194fd3ea75..b7cc39ca65 100644
--- a/recaptcha_enterprise/demosite/app/config.properties
+++ b/recaptcha_enterprise/demosite/app/config.properties
@@ -1,4 +1,3 @@
-recaptcha_action.home=home
recaptcha_action.login=log_in
recaptcha_action.signup=sign_up
recaptcha_action.store=check_out
diff --git a/recaptcha_enterprise/demosite/app/controllers/controller.js b/recaptcha_enterprise/demosite/app/controllers/controller.js
index 19580e0bee..02beff5258 100644
--- a/recaptcha_enterprise/demosite/app/controllers/controller.js
+++ b/recaptcha_enterprise/demosite/app/controllers/controller.js
@@ -66,50 +66,6 @@ const comment = (req, res) => {
};
const {createAssessment} = require('../recaptcha/createAssessment');
-// On homepage load, execute reCAPTCHA Enterprise assessment and take action according to the score.
-const onHomepageLoad = async (req, res) => {
- try {
- //
- const recaptchaAction = PROPERTIES.get('recaptcha_action.home');
- const assessmentResponse = await createAssessment(
- context.project_id,
- context.site_key,
- req.body.token,
- recaptchaAction
- );
-
- // Check if the token is valid, score is above threshold score and the action equals expected.
- // Take action based on the result (BAD / NOT_BAD).
- //
- // If result.label is NOT_BAD:
- // Load the home page.
- // Business logic.
- //
- // If result.label is BAD:
- // Trigger email/ phone verification flow.
- const result = checkForBadAction(assessmentResponse, recaptchaAction);
- //
-
- // Below code is only used to send response to the client for demo purposes.
- // DO NOT send scores or other assessment response to the client.
- // Return the response.
- result.score =
- assessmentResponse.riskAnalysis && assessmentResponse.riskAnalysis.score
- ? assessmentResponse.riskAnalysis.score.toFixed(1)
- : (0.0).toFixed(1);
-
- res.json({
- data: result,
- });
- } catch (e) {
- res.json({
- data: {
- error_msg: e,
- },
- });
- }
-};
-
// On signup button click, execute reCAPTCHA Enterprise assessment and take action according to the score.
const onSignup = async (req, res) => {
try {
@@ -323,7 +279,6 @@ module.exports = {
login,
store,
comment,
- onHomepageLoad,
onSignup,
onLogin,
onStoreCheckout,
diff --git a/recaptcha_enterprise/demosite/app/routes.js b/recaptcha_enterprise/demosite/app/routes.js
index 4fcdb6f308..90d2b5caa5 100644
--- a/recaptcha_enterprise/demosite/app/routes.js
+++ b/recaptcha_enterprise/demosite/app/routes.js
@@ -21,7 +21,6 @@ const {
login,
store,
comment,
- onHomepageLoad,
onSignup,
onLogin,
onStoreCheckout,
@@ -36,7 +35,6 @@ router.get('/store', store);
router.get('/comment', comment);
// Submit action URL rules.
-router.post('/on_homepage_load', onHomepageLoad);
router.post('/on_signup', onSignup);
router.post('/on_login', onLogin);
router.post('/on_store_checkout', onStoreCheckout);
diff --git a/recaptcha_enterprise/demosite/app/static/demo-6df0841a.js b/recaptcha_enterprise/demosite/app/static/demo-2af4c10e.js
similarity index 99%
rename from recaptcha_enterprise/demosite/app/static/demo-6df0841a.js
rename to recaptcha_enterprise/demosite/app/static/demo-2af4c10e.js
index 45c3c6845f..e1c57ae5ce 100644
--- a/recaptcha_enterprise/demosite/app/static/demo-6df0841a.js
+++ b/recaptcha_enterprise/demosite/app/static/demo-2af4c10e.js
@@ -3974,7 +3974,7 @@ class RecaptchaDemo extends s {
Play the game, search the store, view the source, or just poke around
and have fun!
-