Avoid setting reCAPTCHA token on failed execute#11503
Merged
Conversation
changelog: Internal, Anti-Fraud, Avoid setting reCAPTCHA token on failed execute
If this were set previously, we'd get TypeScript warnings on attempting to assign potentially-undefined value to input field
aduth
commented
Nov 13, 2024
| const { recaptchaSiteKey: siteKey, recaptchaAction: action } = this; | ||
|
|
||
| let token; | ||
| let token: string | undefined; |
Contributor
Author
There was a problem hiding this comment.
If this TypeScript type were assigned previously, it'd also have been flagged as an issue:
app/javascript/packages/captcha-submit-button/captcha-submit-button-element.ts:65:7 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
65 this.tokenInput.value = token;
~~~~~~~~~~~~~~~~~~~~~
zachmargolis
approved these changes
Nov 13, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 Summary of changes
Updates the implementation of the reCAPTCHA submit button to avoid setting a token value if reCAPTCHA fails to execute.
Previously, if reCAPTCHA failed to execute (throws an error), the value would be
undefined, which would be stringified to the form input as the literal string"undefined". By not setting the token value, we can get more accurate error details on the backend for a "blank" form error reason (source).📜 Testing Plan
Previously, this would fail with:
Verify token is sent empty for failed reCAPTCHA execute:
recaptcha_tokenis empty, rather than"undefined"