Skip to content

Cleanup captcha - #23118

Merged
ErisDS merged 9 commits into
mainfrom
cleanup-captcha
Apr 30, 2025
Merged

ErisDS merged 9 commits into
mainfrom
cleanup-captcha

Conversation

@ErisDS

@ErisDS ErisDS commented Apr 30, 2025

Copy link
Copy Markdown
Member

ref https://linear.app/ghost/issue/BAE-424/cleanup-captcha

  • We're not moving forward with the captcha feature at this time
  • Therefore, I'm removing all the related code
  • The related PR is split out into various commits so it should be easier to reason about adding it back later if we want to.

@coderabbitai

coderabbitai Bot commented Apr 30, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This change completely removes hCaptcha (captcha) support from both the Ghost core and Portal apps. It deletes all backend logic, configuration, database settings, feature flags, and API integration for captcha. The migration script removes the captcha_enabled setting from the database. The CaptchaService class and its middleware are deleted, and all references to captcha verification are removed from the members API and signup/signin flows. The frontend and admin interfaces are updated to eliminate all UI elements, helpers, and conditional logic related to captcha, including the removal of the hCaptcha React component, mocks, and related dependencies from Portal. All tests covering captcha functionality at both the unit and integration levels are deleted. The public settings allowlist, schema, and documentation are updated to reflect the removal of the captcha setting. The overall result is a codebase with no remaining support or references to captcha functionality.

Possibly related PRs

Suggested labels

browser-tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/portal/src/App.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-i18next".

(The package "eslint-plugin-i18next" was not found when loaded as a Node module from the directory "/apps/portal".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-i18next@latest --save-dev

The plugin "eslint-plugin-i18next" was referenced from the config file in "apps/portal/package.json".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

apps/portal/src/tests/data-attributes.test.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-i18next".

(The package "eslint-plugin-i18next" was not found when loaded as a Node module from the directory "/apps/portal".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-i18next@latest --save-dev

The plugin "eslint-plugin-i18next" was referenced from the config file in "apps/portal/package.json".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

apps/portal/src/actions.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-i18next".

(The package "eslint-plugin-i18next" was not found when loaded as a Node module from the directory "/apps/portal".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-i18next@latest --save-dev

The plugin "eslint-plugin-i18next" was referenced from the config file in "apps/portal/package.json".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 5 others

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 722fe55 and 5e28f45.

⛔ Files ignored due to path filters (4)
  • ghost/core/test/e2e-api/admin/__snapshots__/config.test.js.snap is excluded by !**/*.snap
  • ghost/core/test/e2e-api/content/__snapshots__/settings.test.js.snap is excluded by !**/*.snap
  • ghost/core/test/e2e-api/shared/__snapshots__/version.test.js.snap is excluded by !**/*.snap
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (31)
  • apps/admin-x-settings/src/components/settings/advanced/SpamFilters.tsx (2 hunks)
  • apps/portal/__mocks__/@hcaptcha/react-hcaptcha.js (0 hunks)
  • apps/portal/package.json (0 hunks)
  • apps/portal/src/App.js (3 hunks)
  • apps/portal/src/actions.js (2 hunks)
  • apps/portal/src/components/PopupModal.js (1 hunks)
  • apps/portal/src/components/pages/SigninPage.js (0 hunks)
  • apps/portal/src/data-attributes.js (3 hunks)
  • apps/portal/src/tests/SigninFlow.test.js (0 hunks)
  • apps/portal/src/tests/SignupFlow.test.js (0 hunks)
  • apps/portal/src/tests/data-attributes.test.js (1 hunks)
  • apps/portal/src/utils/fixtures-generator.js (2 hunks)
  • apps/portal/src/utils/helpers.js (0 hunks)
  • ghost/core/core/frontend/helpers/ghost_head.js (0 hunks)
  • ghost/core/core/server/api/endpoints/settings-public.js (1 hunks)
  • ghost/core/core/server/api/endpoints/utils/serializers/input/settings.js (0 hunks)
  • ghost/core/core/server/data/migrations/versions/5.119/2025-04-30-13-01-28-remove-captcha-setting.js (1 hunks)
  • ghost/core/core/server/data/schema/default-settings/default-settings.json (0 hunks)
  • ghost/core/core/server/services/members/CaptchaService.js (0 hunks)
  • ghost/core/core/server/services/members/api.js (1 hunks)
  • ghost/core/core/server/services/members/members-api/members-api.js (1 hunks)
  • ghost/core/core/shared/config/defaults.json (1 hunks)
  • ghost/core/core/shared/labs.js (0 hunks)
  • ghost/core/core/shared/settings-cache/CacheManager.js (0 hunks)
  • ghost/core/core/shared/settings-cache/public.js (0 hunks)
  • ghost/core/package.json (0 hunks)
  • ghost/core/test/e2e-api/content/settings.test.js (0 hunks)
  • ghost/core/test/unit/frontend/helpers/ghost_head.test.js (0 hunks)
  • ghost/core/test/unit/server/data/exporter/index.test.js (1 hunks)
  • ghost/core/test/unit/server/data/schema/integrity.test.js (1 hunks)
  • ghost/core/test/unit/server/services/members/CaptchaService.test.js (0 hunks)
💤 Files with no reviewable changes (17)
  • ghost/core/core/shared/labs.js
  • ghost/core/test/e2e-api/content/settings.test.js
  • ghost/core/core/shared/settings-cache/CacheManager.js
  • ghost/core/core/server/api/endpoints/utils/serializers/input/settings.js
  • apps/portal/package.json
  • apps/portal/src/utils/helpers.js
  • ghost/core/package.json
  • ghost/core/core/server/data/schema/default-settings/default-settings.json
  • ghost/core/core/shared/settings-cache/public.js
  • ghost/core/core/frontend/helpers/ghost_head.js
  • apps/portal/src/tests/SigninFlow.test.js
  • ghost/core/test/unit/server/services/members/CaptchaService.test.js
  • apps/portal/mocks/@hcaptcha/react-hcaptcha.js
  • ghost/core/test/unit/frontend/helpers/ghost_head.test.js
  • apps/portal/src/tests/SignupFlow.test.js
  • ghost/core/core/server/services/members/CaptchaService.js
  • apps/portal/src/components/pages/SigninPage.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Setup
🔇 Additional comments (23)
ghost/core/test/unit/server/data/exporter/index.test.js (1)

239-239: Correct update to allowedKeysLength following captcha removal.

The reduction of allowedKeysLength from 91 to 90 properly reflects the removal of the captcha_enabled setting from the default settings, which is consistent with the PR objective of removing all captcha-related functionality from the codebase.

ghost/core/core/shared/config/defaults.json (1)

133-133: Confirmed removal of captcha configuration from spam settings

The "captcha_enabled": false setting has been removed from the spam section, which aligns with the PR objective to completely remove the captcha feature from the codebase.

apps/portal/src/App.js (3)

26-26: Removed captchaRef from DEV_MODE_DATA

The captchaRef field has been properly removed from the DEV_MODE_DATA constant, aligning with the overall removal of captcha functionality.


61-62: Removed captchaRef from component state

Correctly removed the captchaRef field from the component's initial state in the constructor.


961-961: Removed captchaRef from state destructuring in getContextFromState

The captchaRef field has been properly removed from the state destructuring, ensuring it's no longer included in the context object returned by this method.

apps/portal/src/tests/data-attributes.test.js (1)

632-632: Captcha-related tests removed

The tests associated with captcha functionality have been properly removed, which is consistent with the overall PR objective of removing captcha support.

ghost/core/core/server/services/members/members-api/members-api.js (1)

75-75: Removed captchaService parameter from MembersAPI function

The captchaService parameter has been correctly removed from the MembersAPI function signature. This change is part of the broader removal of captcha functionality from the codebase.

This elimination of the captcha parameter is consistent with the removal of captcha verification middleware from the magic link sending process.

ghost/core/core/server/api/endpoints/settings-public.js (1)

17-22: Successfully removed Captcha integration from settings-public.js

The captcha settings have been completely removed from the object returned by the query method, which is consistent with the overall goal of removing the captcha feature.

ghost/core/core/server/services/members/api.js (1)

236-242: Properly removed captchaService from MembersApi initialization

The captchaService and its related dependencies have been successfully removed from the object passed to MembersApi, which aligns with the PR objective of cleaning up captcha functionality.

ghost/core/core/server/data/migrations/versions/5.119/2025-04-30-13-01-28-remove-captcha-setting.js (1)

1-3: Migration script for captcha removal is well implemented

This migration script correctly uses the removeSetting utility to remove the 'captcha_enabled' setting from the database, which is a clean approach for handling the database changes needed for the captcha cleanup.

apps/portal/src/components/PopupModal.js (2)

9-9: Properly removed captcha-related imports

The helpers related to captcha (hasCaptchaEnabled and getCaptchaSitekey) have been successfully removed from the import list, consistent with the PR's objective of cleaning up captcha functionality.


143-234: Successfully removed captcha rendering from PopupModal component

The renderHCaptcha method and its call within the component's render method have been removed, completing the cleanup of captcha-related code in this component.

apps/portal/src/utils/fixtures-generator.js (2)

46-47: Trailing comma removed after removing captcha parameters

This change properly removes the trailing comma after recommendationsEnabled in the function parameters, as part of removing the captcha-related parameters that previously followed it.


72-75: Removed captcha properties from return object

The trailing comma after posts was correctly removed as part of cleaning up the return object after removing the captcha-related properties (captcha_enabled and captcha_sitekey).

apps/portal/src/actions.js (3)

3-3: Import updated to remove captcha helpers

The import statement was properly updated to remove the captcha-related helper functions, aligning with the removal of captcha functionality.


81-83: Simplified signin function by removing captcha logic

The signin function has been streamlined by removing the captcha verification step, which simplifies the authentication flow.


102-106: Simplified signup function by removing captcha logic

The signup function implementation has been cleaned up to remove the captcha verification step, consistent with the PR objective of removing captcha functionality.

apps/admin-x-settings/src/components/settings/advanced/SpamFilters.tsx (2)

4-5: Imports simplified after captcha removal

The import statements have been correctly updated to remove captcha-related components and dependencies.


76-77: UI element for captcha settings removed

The SpamFilters component now focuses solely on blocked email domains, with all captcha-related UI elements and functionality removed. This change is consistent with the broader removal of captcha features.

apps/portal/src/data-attributes.js (3)

2-2: Import updated to remove captcha helpers

The import statement was appropriately modified to remove the captcha-related helper functions, consistent with the removal of captcha functionality.


18-20: Simplified formSubmitHandler signature

The function signature has been streamlined by removing the captchaId parameter, which is no longer needed after removing captcha functionality.


194-195: Updated submitHandler to remove captcha parameter

The call to formSubmitHandler has been correctly updated to remove the captcha-related parameter, ensuring that the form submission flow no longer includes captcha verification.

ghost/core/test/unit/server/data/schema/integrity.test.js (1)

40-40:

Details

❌ Incorrect review comment

Update expected settings hash after removal of captcha_enabled.

The expected MD5 hash has been updated to '96d23249b355f359c7d349da38ab5f15' to reflect the removal of the captcha_enabled entry from default-settings.json. Please verify that this new hash matches the contents of the modified file.


🏁 Script executed:

#!/usr/bin/env bash
# Compute MD5 of default-settings.json for integrity test
md5sum core/server/data/schema/default-settings/default-settings.json

Length of output: 169


🏁 Script executed:

#!/usr/bin/env bash
# Locate default-settings.json in the repository and compute its MD5 hash
echo "Searching for default-settings.json..."
find . -type f -iname default-settings.json

echo ""
for file in $(find . -type f -iname default-settings.json); do
  echo "MD5 for $file:"
  md5sum "$file"
done

Length of output: 1107


🏁 Script executed:

#!/usr/bin/env bash
# Display the integrity test to see which default-settings.json is used
echo "===== integrity.test.js (lines 1-200) ====="
sed -n '1,200p' ghost/core/test/unit/server/data/schema/integrity.test.js

Length of output: 3502


🏁 Script executed:

#!/usr/bin/env bash
# Compute MD5 hash of JSON.stringify(defaultSettings) as used in integrity.test.js
file="ghost/core/core/server/data/schema/default-settings/default-settings.json"

echo "Using file: $file"
echo -n "MD5(JSON.stringify(defaultSettings)): "
node -e "
  const crypto = require('crypto');
  const defaultSettings = require(process.argv[1]);
  const hash = crypto
    .createHash('md5')
    .update(JSON.stringify(defaultSettings), 'binary')
    .digest('hex');
  process.stdout.write(hash);
" "$file"

Length of output: 1523


🏁 Script executed:

#!/usr/bin/env bash
# Compute the MD5 hash of JSON.stringify(defaultSettings) as used in integrity.test.js
file="ghost/core/core/server/data/schema/default-settings/default-settings.json"

echo "Using file: $file"
echo -n "MD5(JSON.stringify(defaultSettings)): "
node -e 'const crypto=require("crypto"), fs=require("fs");
const defaultSettings = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
const hash = crypto.createHash("md5").update(JSON.stringify(defaultSettings), "binary").digest("hex");
console.log(hash);' "$file"

Length of output: 719


Ignore hash update suggestion for default-settings.json

The MD5 of the current default-settings.json (as JSON-stringified) is still 5eb97fee379c1d0420de58957d29fe26, which matches the existing currentSettingsHash. No removal of captcha_enabled or other changes have been detected in this file, so the proposed hash 96d23249b355f359c7d349da38ab5f15 is incorrect. Please disregard this update.

Likely an incorrect or invalid review comment.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot added the migration [pull request] Includes migration for review label Apr 30, 2025
@github-actions

Copy link
Copy Markdown
Contributor

It looks like this PR contains a migration 👀
Here's the checklist for reviewing migrations:

General requirements

  • ⚠️ Tested on the staging database servers
  • Satisfies idempotency requirement (both up() and down())
  • Does not reference models
  • Filename is in the correct format (and correctly ordered)
  • Targets the next minor version
  • All code paths have appropriate log messages
  • Uses the correct utils
  • Contains a minimal changeset
  • Does not mix DDL/DML operations
  • Tested in MySQL and SQLite

Schema changes

  • Both schema change and related migration have been implemented
  • For index changes: has been performance tested for large tables
  • For new tables/columns: fields use the appropriate predefined field lengths
  • For new tables/columns: field names follow the appropriate conventions
  • Does not drop a non-alpha table outside of a major version

Data changes

  • Mass updates/inserts are batched appropriately
  • Does not loop over large tables/datasets
  • Defends against missing or invalid data
  • For settings updates: follows the appropriate guidelines

@ErisDS
ErisDS merged commit 1091014 into main Apr 30, 2025
@ErisDS
ErisDS deleted the cleanup-captcha branch April 30, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

migration [pull request] Includes migration for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant