diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-06-07 14:24:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-07 14:24:04 +0100 |
commit | 6d4bd5d890eeab47bddfad5a48d37766f954171f (patch) | |
tree | 994aa7168cc614894b632ef70f1779baec90a920 /mediaapi | |
parent | 27948fb30468315ce613402dc8cc1fa7dba01679 (diff) |
Rate limiting changes (#2519)
* Rate limiting changes
This makes the following changes:
* For logged in users, the rate limiting now applies to the device session rather than the remote IP address;
* For non-logged in users, the rate limiting continues to apply to remote address as it does today;
* It is now possible to add user IDs to the `exempt_user_ids` option under `rate_limiting` to exclude bots from rate limiting;
* Admin and appservice users are now exempt from rate limiting by default.
* Fix build with media API
Diffstat (limited to 'mediaapi')
-rw-r--r-- | mediaapi/routing/routing.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/mediaapi/routing/routing.go b/mediaapi/routing/routing.go index 76f07415..19690818 100644 --- a/mediaapi/routing/routing.go +++ b/mediaapi/routing/routing.go @@ -62,7 +62,7 @@ func Setup( uploadHandler := httputil.MakeAuthAPI( "upload", userAPI, func(req *http.Request, dev *userapi.Device) util.JSONResponse { - if r := rateLimits.Limit(req); r != nil { + if r := rateLimits.Limit(req, dev); r != nil { return *r } return Upload(req, cfg, dev, db, activeThumbnailGeneration) @@ -70,7 +70,7 @@ func Setup( ) configHandler := httputil.MakeAuthAPI("config", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { - if r := rateLimits.Limit(req); r != nil { + if r := rateLimits.Limit(req, device); r != nil { return *r } respondSize := &cfg.MaxFileSizeBytes @@ -126,7 +126,7 @@ func makeDownloadAPI( // Ratelimit requests // NOTSPEC: The spec says everything at /media/ should be rate limited, but this causes issues with thumbnails (#2243) if name != "thumbnail" { - if r := rateLimits.Limit(req); r != nil { + if r := rateLimits.Limit(req, nil); r != nil { if err := json.NewEncoder(w).Encode(r); err != nil { w.WriteHeader(http.StatusInternalServerError) return |