generated from pagopa/terraform-infrastructure-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [CHK-3719] enable recaptcha for checkout auth service login api (…
…#2806) * feat: enable recaptcha check for checkout login api * chore: remove comment * chore: remove comment * feat: adding rate limit to the login inbound policies * chore: policy api name construction * fix: renaming checkout api group * fix: renaming checkout api group - using local values * fix: redefine inbound policies for checkout auth service * chore: use locals to centralize api-related value definition * chore: pre-commit run * fix: change recaptcha secret named value * fix: google recaptcha secrets fix * fix: fixing api name in operation policy for checkout auth service --------- Co-authored-by: Simone infante <[email protected]> Co-authored-by: ciuffagianluca <[email protected]> Co-authored-by: Pietro Tota <[email protected]>
- Loading branch information
1 parent
62176d0
commit 3bf7afc
Showing
4 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/domains/checkout-app/api/checkout/checkout_auth_service/v1/_base_policy.xml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/domains/checkout-app/api/checkout/checkout_auth_service/v1/_recaptcha_check.xml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<policies> | ||
<inbound> | ||
<base /> | ||
<!-- Check google reCAPTCHA token validity START --> | ||
<set-variable name="recaptchaSecret" value="{{ecommerce-for-checkout-google-recaptcha-secret}}" /> | ||
<set-variable name="recaptchaToken" value="@(context.Request.OriginalUrl.Query.GetValueOrDefault("recaptcha"))" /> | ||
<choose> | ||
<when condition="@(context.Variables["recaptchaToken"] == null || context.Variables["recaptchaToken"] == "")"> | ||
<return-response> | ||
<set-status code="401" reason="Unauthorized" /> | ||
</return-response> | ||
</when> | ||
</choose> | ||
<send-request ignore-error="true" timeout="10" response-variable-name="recaptcha-check" mode="new"> | ||
<set-url>https://www.google.com/recaptcha/api/siteverify</set-url> | ||
<set-method>POST</set-method> | ||
<set-header name="Content-Type" exists-action="override"> | ||
<value>application/x-www-form-urlencoded</value> | ||
</set-header> | ||
<set-body>@($"secret={(string)context.Variables["recaptchaSecret"]}&response={(string)context.Variables["recaptchaToken"]}")</set-body> | ||
</send-request> | ||
<set-variable name="recaptcha-check-body" value="@(((IResponse)context.Variables["recaptcha-check"]).Body.As<JObject>())" /> | ||
<choose> | ||
<when condition="@(((IResponse)context.Variables["recaptcha-check"]).StatusCode != 200 || ((bool) ((JObject) context.Variables["recaptcha-check-body"])["success"]) != true)"> | ||
<return-response> | ||
<set-status code="401" reason="Unauthorized" /> | ||
</return-response> | ||
</when> | ||
</choose> | ||
<!-- Check google reCAPTCHA token validity END --> | ||
</inbound> | ||
<outbound> | ||
<base /> | ||
</outbound> | ||
<backend> | ||
<base /> | ||
</backend> | ||
<on-error> | ||
<base /> | ||
</on-error> | ||
</policies> |