Repository navigation
fix: [OCISDEV-825] Rate-limit the exportPersonalData endpoint - #12519
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
dj4oC
left a comment
There was a problem hiding this comment.
Adds a 5-req/min rate limit to POST /v1.0/users/{userID}/exportPersonalData in the Graph service to mitigate an authenticated app-level DoS (#12516), via a newly-vendored go-chi/httprate, keyed by httprate.KeyByEndpoint (the raw r.URL.Path).
Findings
Security (blocking). Confirmed by reading services/graph/pkg/service/v0/service.go and personaldata.go on the PR branch: the rate-limit middleware is attached via r.With(...) and therefore runs before ExportPersonalData's own "uid mismatch" check (personaldata.go:47-52). Since the limiter's key is r.URL.Path — which contains the target {userID} segment, not the caller's authenticated identity — any authenticated user can grief a specific victim by POSTing /v1.0/users/{victimID}/exportPersonalData up to 5×/min. Each request gets rejected with 400 ("personal data export for other users are not permitted"), but it still consumes the victim's rate-limit budget, since that check only happens in the handler, after the limiter. After 5 such attacker requests, the real victim gets 429 on their own legitimate export. GET /v1.0/users (service.go:303) carries no requireAdmin gate, so target userIDs are discoverable by any authenticated user — this is practical, not theoretical. Recommend keying the limiter off the authenticated caller's ID (already available via context from upstream auth middleware) instead of the URL path, so the mitigation can't be turned into a cross-user denial-of-service tool.
Also raised independently by the security/stability passes: the counter is in-memory/per-process (vendor/github.com/go-chi/httprate/local_counter.go), so in a horizontally-scaled Graph deployment the effective limit becomes 5 × replica count, not a hard global 5/min. Not blocking by itself, but worth a one-line callout in the changelog so operators don't assume a global guarantee.
Stability. Verified the /me alias (service.go:292-301) does not register exportPersonalData, so there's no accidental bucket-sharing via that route. No other regressions found.
Performance. No blocking issues — call volume is inherently low for a data-export endpoint; the added mutex/map overhead and the one allocation from JoinKeys's internal strings.Builder (invoked even with a single key function) are both negligible at this scale.
Test coverage. The new unit test (personaldata_ratelimit_test.go) verifies the middleware composition in isolation via a hand-built flat router, not NewService()'s real nested route tree, and it only ever calls the endpoint as the matching user — it never simulates the cross-user griefing case above, so it would not have caught it. Recommend adding a test where user A's requests target user B's path, plus (per policy) an integration/e2e test exercising the real NewService() mux for the externally-observable 429/Retry-After behavior.
Deployment topology check
Concern — the in-memory-only counter weakens the guarantee under k8s multi-pod/multi-replica scaling of the Graph service (see above). Not blocking on its own, but should be called out in docs/changelog.
Verdict
Changes requested — the rate-limit key should be derived from the authenticated caller, not the target-URL path, to close the cross-user griefing vector before this merges.
🤖 Automated review by Claude Code (security · stability · performance · coverage)
Generated by Claude Code
Regarding the feedback on the in-memory vs. distributed (shared cache) rate limiter, I would like to clarify why a distributed implementation is not practical or necessary for this specific endpoint:
|
|
Thanks for the detailed load-test data — the argument about in-memory vs. distributed rate-limiting (concern #2 in the review) is well-reasoned and I agree the operational complexity isn't worth it for this endpoint. That concern is withdrawn. The blocking concern (concern #1) is a separate issue that still needs addressing before merge: The rate-limit key is currently the target URL path — specifically the victim's Any authenticated user can send The fix is small: replace // Instead of:
httprate.LimitByIP(5, time.Minute) // or KeyByEndpoint
// Key by authenticated caller, not target URL:
httprate.NewRateLimiter(5, time.Minute, &httprate.Options{
KeyFuncs: []httprate.KeyFunc{func(r *http.Request) (string, error) {
// extract from context — auth middleware populates this
if uid := middleware.UserIDFromContext(r.Context()); uid != "" {
return uid, nil
}
return httprate.KeyByIP(r) // fallback
}},
})Concern #2 (in-memory / per-replica): accepted, no change needed. 🤖 Automated review by Claude Code (security · stability · performance · coverage) |
Checking user ID is not a rate limiter's responsibility, it is a validation responsibility. We shouldn't mix it. |
I'd separate two different things that are getting conflated here:
Concretely: with the current If the team's call is to accept this as a known, low-severity tradeoff rather than change the key, that's a legitimate maintainer risk-acceptance decision — but it should be an explicit sign-off from a human maintainer rather than this thread converging on "no change" by attrition. Leaving this PR's review at Changes requested pending that decision. 🤖 Automated review by Claude Code (security · stability · performance · coverage) Generated by Claude Code |
af1f5d1 to
0c15d8c
Compare
|
Update after re-checking the current head commit ( Concern #1 (cross-user griefing via URL-path key) — resolved. The latest push extracted the "uid mismatch" check out of the handler into a new Residual, non-blocking: Withdrawing "changes requested" — no remaining objection to merging as-is. 🤖 Automated review by Claude Code (security · stability · performance · coverage) Generated by Claude Code |
dj4oC
left a comment
There was a problem hiding this comment.
Re-reviewed at current head (7dc5ba8). The blocking concern from my earlier review (rate-limit key derived from attacker-controlled URL path, enabling cross-user budget griefing) is resolved: RequireSelfUserID middleware now runs before the rate limiter and rejects cross-user requests before they can consume the limiter's budget. See inline comment for the residual non-blocking test-coverage note (the unit test doesn't exercise the composed middleware chain).
Verdict
Approved — withdrawing the earlier changes-requested.
🤖 Automated review by Claude Code (security · stability · performance · coverage)
Generated by Claude Code
* fix: Rate-limit the exportPersonalData endpoint * fix: the RequreSelfUserID validation middleware added Signed-off-by: Michal Klos <[email protected]>
* fix: [OCISDEV-810] fix the space role and custom role checks (#12540) * fix: [OCISDEV-810] fix the space role and custom role checks * test: [OCISDEV-810] expect 400 when updating a share to a disabled role The update (PATCH) permission handlers now enforce the admin role allowlist, consistent with invite. Updating a share to a disabled role (Secure Viewer, Denied, Space Editor Without Versions) therefore returns 400 instead of the previous silent 200. Update the @issue-10768 scenarios to assert the new, correct behavior. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]> Signed-off-by: Michal Klos <[email protected]> * WIP: bump reva pin to backport/8.0/security-fixes-consolidated tip (OCISDEV-810) Pins to reva@72978fc55553 (prerequisite #631 + OCISDEV-810 #653 on reva's stable-8.0 consolidated backport branch) purely to exercise ocis CI against the fix before reva's PR merges. Re-pin to the merged commit once reva#806 lands. Signed-off-by: Michal Klos <[email protected]> * FIX[OCISDEV-809]: encrypt viewOnlyToken (#12558) fix(OCIDDEV-809): encrypt viewOnlyToken in the WOPI token Signed-off-by: Michal Klos <[email protected]> * feat: [OCISDEV-720] fix public link (#12332) Signed-off-by: Michal Klos <[email protected]> * WIP: bump reva pin to backport/8.0/security-fixes-consolidated tip (OCISDEV-720) Pins to reva@4f9a7ac25cfc (OCISDEV-971 + OCISDEV-720 on reva's stable-8.0 consolidated backport branch) purely to exercise ocis CI against the fix before reva's PR merges. Re-pin to the merged commit once reva#806 lands. Signed-off-by: Michal Klos <[email protected]> * fix: [OCISDEV-1404] harden public link brute force protection (#12944) The proxy public share authenticator set the brute force protection skip marker on every authentication, including requests where the proxy is the only authenticator. Failed password attempts on those requests were never counted, so the rate limit for password protected public links was not enforced. The skip marker is now only set for requests that are re-authenticated downstream, so failed attempts are reliably counted and the throttle is applied consistently. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Michal Klos <[email protected]> * fix: [OCISDEV-750] Prevent error information disclosure (#12398) Signed-off-by: Michal Klos <[email protected]> * fix: [OCISDEV-825] Rate-limit the exportPersonalData endpoint (#12519) * fix: Rate-limit the exportPersonalData endpoint * fix: the RequreSelfUserID validation middleware added Signed-off-by: Michal Klos <[email protected]> * fix: private user information available only for admin and the user (#12327) * fix: private user information available only for admin and the user * fix: adjust unit tests Signed-off-by: Michal Klos <[email protected]> --------- Signed-off-by: Michal Klos <[email protected]> Co-authored-by: Roman Perekhod <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Firas Frikha <[email protected]> Co-authored-by: Roman Perekhod <[email protected]> Co-authored-by: Awab Abdoun <[email protected]> Co-authored-by: Juan Pablo Villafañez <[email protected]>
Bugfix: Rate-limit the exportPersonalData endpoint
We've added a rate limit to the
exportPersonalDataendpoint to mitigate an authenticated application-level denial-of-service.
Rate-limit per endpoint path carries the userID, so effectively per user.
The endpoint is now limited to 5 requests per minute.