-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(rate-limiting,response-ratelimiting) config option: hide/omit rate headers sent to client #2087
Conversation
For the new config item, omit_client_headers or another name would be fine too: I'm open to suggestions. |
lgtm let's wait for 0.10 release first before merging |
Great, thank you for taking a look! |
@jdmonin can you rebase this PR against |
ac66f4b
to
7ea8229
Compare
@p0pr0ck5 Thanks for your patience! Rebased and tested. |
if not conf.hide_client_headers then | ||
ngx.header[RATELIMIT_LIMIT.."-"..limit_name.."-"..period_name] = lv.limit | ||
ngx.header[RATELIMIT_REMAINING.."-"..limit_name.."-"..period_name] = math_max(0, lv.remaining - (increments[limit_name] and increments[limit_name] or 0)) -- increment_value for this current request | ||
end | ||
|
||
if increments[limit_name] and increments[limit_name] > 0 and lv.remaining <= 0 then | ||
stop = true -- No more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thought here: should exit early out of this loop (via break
) if we are omitting headers, and we've reached this condition? Once we've assigned stop = true
, we're not doing any other work aside from assigning headers, so breakingnoit early would save some work. Don't know if this is worth it though, so this isn't a blocker to me, just a thought.
Summary
Add a config option to the rate-limiting and response-ratelimiting plugins to not send the rate-related headers (limit and remaining) normally sent to the client. For publicly exposed APIs, this can be useful for security.
Full changelog