diff --git a/services/web/app/src/Features/UserContentDomainCheck/UserContentDomainController.js b/services/web/app/src/Features/UserContentDomainCheck/UserContentDomainController.js index 31da7e39d0..bcce34a955 100644 --- a/services/web/app/src/Features/UserContentDomainCheck/UserContentDomainController.js +++ b/services/web/app/src/Features/UserContentDomainCheck/UserContentDomainController.js @@ -15,7 +15,13 @@ function recordFallbackUsage(_req, res) { res.sendStatus(204) } +function recordMaxAccessChecksHit(_req, res) { + Metrics.inc('user_content_domain_max_access_checks_hit') + res.sendStatus(204) +} + module.exports = { recordCheckResult, recordFallbackUsage, + recordMaxAccessChecksHit, } diff --git a/services/web/app/src/router.js b/services/web/app/src/router.js index 5465d1b307..679fbcb460 100644 --- a/services/web/app/src/router.js +++ b/services/web/app/src/router.js @@ -214,6 +214,10 @@ const rateLimiters = { points: 15, duration: 60, }), + userContentDomainMaxAccessChecksHit: new RateLimiter('user-content-mach', { + points: 15, + duration: 60, + }), } function initialize(webRouter, privateApiRouter, publicApiRouter) { @@ -1358,6 +1362,13 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) { ), UserContentDomainController.recordFallbackUsage ) + webRouter.post( + '/record-user-content-domain-max-access-checks-hit', + RateLimiterMiddleware.rateLimit( + rateLimiters.userContentDomainMaxAccessChecksHit + ), + UserContentDomainController.recordMaxAccessChecksHit + ) webRouter.get( `/read/:token(${TokenAccessController.READ_ONLY_TOKEN_PATTERN})`, diff --git a/services/web/frontend/js/features/user-content-domain-access-check/index.ts b/services/web/frontend/js/features/user-content-domain-access-check/index.ts index 4eda09b8d4..f782a96352 100644 --- a/services/web/frontend/js/features/user-content-domain-access-check/index.ts +++ b/services/web/frontend/js/features/user-content-domain-access-check/index.ts @@ -278,6 +278,9 @@ export function scheduleUserContentDomainAccessCheck() { return scheduleUserContentDomainAccessCheck() } if (accessCheckPassed) return + if (remainingChecks === 0) { + recordMaxAccessChecksHit() + } if (remainingChecks-- <= 0) return checkUserContentDomainAccess() .then(ok => { @@ -288,3 +291,7 @@ export function scheduleUserContentDomainAccessCheck() { }) }, INITIAL_DELAY_MS) } + +function recordMaxAccessChecksHit() { + postJSON('/record-user-content-domain-max-access-checks-hit').catch(() => {}) +}