Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rate limit HTTP OPTIONS requests #458

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/process_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,14 @@ void process_request(request &req, rate_limiter &limiter,
const auto is_moderator = req_ctx.is_moderator();

// check whether the client is being rate limited
if (auto [exceeded_limit, retry_seconds] = limiter.check(client_key, is_moderator);
exceeded_limit) {
logger::message(fmt::format("Rate limiter rejected request from {}", client_key));
throw http::bandwidth_limit_exceeded(retry_seconds);
// skip check in case of HTTP OPTIONS since it interferes with CORS preflight requests
// see https://github.com/facebook/Rapid/issues/1424 for context
if (method != http::method::OPTIONS) {
if (auto [exceeded_limit, retry_seconds] = limiter.check(client_key, is_moderator);
exceeded_limit) {
logger::message(fmt::format("Rate limiter rejected request from {}", client_key));
throw http::bandwidth_limit_exceeded(retry_seconds);
}
}

const auto start_time = std::chrono::high_resolution_clock::now();
Expand Down
Loading