Skip to content

Commit

Permalink
Added Captcha middleware to members send-magic-link API
Browse files Browse the repository at this point in the history
ref BAE-104
  • Loading branch information
sam-lord committed Jan 21, 2025
1 parent 789a55a commit a6d81a7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
6 changes: 6 additions & 0 deletions ghost/core/core/server/services/members/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const tiersService = require('../tiers');
const newslettersService = require('../newsletters');
const memberAttributionService = require('../member-attribution');
const emailSuppressionList = require('../email-suppression-list');
const CaptchaService = require('@tryghost/captcha-service');
const {t} = require('../i18n');
const sentry = require('../../../shared/sentry');
const sharedConfig = require('../../../shared/config');
Expand Down Expand Up @@ -240,6 +241,11 @@ function createApiInstance(config) {
settingsCache,
sentry,
settingsHelpers,
captchaService: new CaptchaService({
enabled: labsService.isSet('captcha') && sharedConfig.get('captcha:enabled'),
scoreThreshold: sharedConfig.get('captcha:scoreThreshold'),
secretKey: sharedConfig.get('captcha:secretKey')
}),
config: sharedConfig
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,7 @@ Object {
"facebook": "ghost",
"firstpromoter_account": null,
"icon": null,
"labs": Object {
"ActivityPub": true,
"NestPlayground": true,
"additionalPaymentMethods": true,
"adminXDemo": true,
"captcha": true,
"collectionsCard": true,
"contentVisibility": true,
"editorExcerpt": true,
"emailCustomization": true,
"importMemberTier": true,
"lexicalIndicators": true,
"mailEvents": true,
"postsX": true,
"stripeAutomaticTax": true,
"urlCache": true,
"webmentions": true,
},
"labs": Any<Object>,
"lang": "en",
"locale": "en",
"logo": null,
Expand Down Expand Up @@ -211,7 +194,7 @@ Object {
"twitter_image": null,
"twitter_title": null,
"url": "http://127.0.0.1:2369/",
"version": "5.106",
"version": Any<String>,
},
}
`;
Expand Down
5 changes: 2 additions & 3 deletions ghost/core/test/e2e-api/content/settings.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
const {anyEtag, anyContentLength, anyContentVersion} = matchers;
const config = require('../../../core/shared/config');
const configUtils = require('../../utils/configUtils');

const settingsMatcher = {
Expand Down Expand Up @@ -51,10 +50,10 @@ describe('Settings Content API', function () {
'content-length': anyContentLength
})
.matchBodySnapshot({
settings: {
settings: Object.assign({}, settingsMatcher, {
captcha_enabled: true,
captcha_sitekey: 'testkey'
}
})
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions ghost/members-api/lib/members-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = function MembersAPI({
settingsCache,
sentry,
settingsHelpers,
captchaService,
config
}) {
const tokenService = new TokenService({
Expand Down Expand Up @@ -337,6 +338,7 @@ module.exports = function MembersAPI({
const middleware = {
sendMagicLink: Router().use(
body.json(),
captchaService.getMiddleware(),
forwardError((req, res) => routerController.sendMagicLink(req, res))
),
createCheckoutSession: Router().use(
Expand Down

0 comments on commit a6d81a7

Please sign in to comment.