Skip to content

feat(pir): captcha providers #1550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 19, 2025
Merged

feat(pir): captcha providers #1550

merged 9 commits into from
Mar 19, 2025

Conversation

madblex
Copy link
Contributor

@madblex madblex commented Mar 7, 2025

Asana Task/Github Issue: https://app.asana.com/0/0/1209555302496203

Description

This PR:

  • refactors the captcha action handlers to enable extensibility (see associated tech design)
  • adds support for existing captcha providers: recaptcha, recaptcha enterprise, captcha (partially)
  • adds scaffolding for cloudflare turnstile
  • adds support for the new navigate action, already augmented with the new injectCaptchaHandler property (see associated tech design)
  • adds resolveActionHandlers resolver for the action handlers that uses a remote config to determine which version is used

TODO:

  • polish up the code, I am still deciding upon some patterns I used, names, etc
  • create remote config and wire up the value in resolveActionHandlers
  • manual testing
  • automated testing
  • reference asana tasks next to TODOs

Testing Steps

  • cd injected
  • npm run playwright should pass

Checklist

Please tick all that apply:

  • I have tested this change locally
  • I have tested this change locally in all supported browsers
  • This change will be visible to users
  • I have added automated tests that cover this change
  • I have ensured the change is gated by config
  • This change was covered by a ship review
  • This change was covered by a tech design
  • Any dependent config has been merged

Copy link

netlify bot commented Mar 7, 2025

Deploy Preview for content-scope-scripts ready!

Name Link
🔨 Latest commit 12b2e90
🔍 Latest deploy log https://app.netlify.com/sites/content-scope-scripts/deploys/67daee0b324c410008c1ab73
😎 Deploy Preview https://deploy-preview-1550--content-scope-scripts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Mar 7, 2025

Temporary Branch Update

The temporary branch has been updated with the latest changes. Below are the details:

Please use the above install command to update to the latest version.

Copy link

github-actions bot commented Mar 7, 2025

[Beta] Generated file diff

Time updated: Wed, 19 Mar 2025 16:17:54 GMT

Android
    - android/brokerProtection.js

File has changed

Integration
    - integration/contentScope.js

File has changed

Windows
    - windows/contentScope.js

File has changed

Apple
    - dist/contentScopeIsolated.js

File has changed

Copy link
Contributor

@shakyShane shakyShane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @madblex for your first contribution!

I like the pattern you're thinking of here, I just noted some small things related to matching the existing codebase's patterns around type-safety etc. Here's a small summary:

    1. try to design richer return types to avoid needing to use exceptions as control flow
    1. favour implements over extends to avoid class inheritance (this is awkward in JSDoc, but I gave an example in the comments)
    1. remove 'index' files if they only serve to enable re-exports. In this codebase it's preferred to be explicit about import/exports.
    1. prefer function foo() { over const foo = () => { in module-level functions

In terms of number 2, I made this change on a branch just to verify the types would still work correctly, you can take a look here bf391d2

@madblex madblex force-pushed the madblex/pir-captcha-providers branch from eed4ba4 to 87d9841 Compare March 11, 2025 11:34
@madblex madblex changed the title [WIP] feat(pir): captcha providers feat(pir): captcha providers Mar 11, 2025
@madblex madblex marked this pull request as ready for review March 11, 2025 11:35
@madblex madblex requested a review from a team as a code owner March 11, 2025 11:35
@madblex madblex force-pushed the madblex/pir-captcha-providers branch from 327c2ea to 18e3a6c Compare March 13, 2025 11:53
@madblex madblex requested review from shakyShane and brianhall March 13, 2025 12:09
brianhall
brianhall previously approved these changes Mar 17, 2025
Copy link
Contributor

@brianhall brianhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madblex This looks great to me. I left some comments and did some testing (see below) but nothing blocking from me.

I tested this PR directly in XCode in the following scenarios:

  1. Using existing Spokeo JSON file (e.g. no captchaType in getCaptchaInfo) - ✅ Succeeded as expected
  2. Using an invalid captchaType in Spokeo's JSON (captchaType: 'bleh') - ❌ Failed as expected
  3. Using an explicit captchaType in Spokeo's JSON (captchaType: 'recaptcha2') - ✅ Succeded as expected
  4. Using a real but mismatched captchaType in Spokeo's JSON (captchaType: 'cloudflareTurnstile') - ✅ Fell back to recaptcha2 and succeeded.

Very excited to see us in a better place captcha-wise. Great job.

@madblex madblex requested a review from brianhall March 18, 2025 08:15
@madblex
Copy link
Contributor Author

madblex commented Mar 18, 2025

@madblex This looks great to me. I left some comments and did some testing (see below) but nothing blocking from me.

I tested this PR directly in XCode in the following scenarios:

  1. Using existing Spokeo JSON file (e.g. no captchaType in getCaptchaInfo) - ✅ Succeeded as expected
  2. Using an invalid captchaType in Spokeo's JSON (captchaType: 'bleh') - ❌ Failed as expected
  3. Using an explicit captchaType in Spokeo's JSON (captchaType: 'recaptcha2') - ✅ Succeded as expected
  4. Using a real but mismatched captchaType in Spokeo's JSON (captchaType: 'cloudflareTurnstile') - ✅ Fell back to recaptcha2 and succeeded.

Very excited to see us in a better place captcha-wise. Great job.

Thanks Brian, and thanks for testing as well! Did a very similar test matrix and it all worked well with the new changes. Ready for another round of reviews.

brianhall
brianhall previously approved these changes Mar 18, 2025
Copy link
Contributor

@brianhall brianhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These updated changes look great to me.

@madblex madblex requested a review from brianhall March 19, 2025 11:12
@madblex madblex force-pushed the madblex/pir-captcha-providers branch from 100438f to 94ce4f6 Compare March 19, 2025 16:00
brianhall
brianhall previously approved these changes Mar 19, 2025
madblex added 3 commits March 19, 2025 17:03
- replace arrow fn with regular functions
- update provider registry
- align getSupportingCodeToInject return types
madblex and others added 5 commits March 19, 2025 17:03
- wire up the remote config setting
- replace querying by root with querying by captcha container
- remove hcaptcha and cloudflare providers
* feat(pir): captcha providers tests

* feat: address PR comments

* feat: amend tests

* fix: add new tests and unroll for loops

* Minor tweaks to wording and removal of hCaptcha mocks

* fix: lint

---------

Co-authored-by: Brian Hall <[email protected]>
@madblex madblex force-pushed the madblex/pir-captcha-providers branch from 94ce4f6 to 304e4db Compare March 19, 2025 16:03
shakyShane
shakyShane previously approved these changes Mar 19, 2025
@madblex madblex dismissed stale reviews from shakyShane and brianhall via 408e7f3 March 19, 2025 16:14
@madblex madblex force-pushed the madblex/pir-captcha-providers branch from 408e7f3 to 12b2e90 Compare March 19, 2025 16:17
@madblex madblex requested review from brianhall and shakyShane March 19, 2025 16:29
@madblex madblex merged commit 4975042 into main Mar 19, 2025
16 checks passed
@madblex madblex deleted the madblex/pir-captcha-providers branch March 19, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants