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

feat(rate-limiting,response-ratelimiting) config option: hide/omit rate headers sent to client #2087

Closed
wants to merge 3 commits into from

Conversation

jdmonin
Copy link
Contributor

@jdmonin jdmonin commented Feb 14, 2017

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

  • Add boolean config option hide_client_headers
  • Add related tests

@jdmonin
Copy link
Contributor Author

jdmonin commented Feb 14, 2017

For the new config item, omit_client_headers or another name would be fine too: I'm open to suggestions.

@jdmonin jdmonin changed the title feat(rate-limiting,response-ratelimiting) config option: hide rate headers sent to client feat(rate-limiting,response-ratelimiting) config option: hide/omit rate headers sent to client Feb 14, 2017
@Tieske
Copy link
Member

Tieske commented Feb 28, 2017

lgtm

let's wait for 0.10 release first before merging

@Tieske Tieske added pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) and removed pr/status/needs review labels Feb 28, 2017
@jdmonin
Copy link
Contributor Author

jdmonin commented Mar 1, 2017

Great, thank you for taking a look!

@p0pr0ck5
Copy link
Contributor

@jdmonin can you rebase this PR against next? There are some merge conflicts.

@p0pr0ck5 p0pr0ck5 added pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. and removed pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) labels Mar 28, 2017
@jdmonin jdmonin force-pushed the feature/rate-limiting-hide-headers branch from ac66f4b to 7ea8229 Compare April 11, 2017 10:07
@jdmonin
Copy link
Contributor Author

jdmonin commented Apr 11, 2017

@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
Copy link
Contributor

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.

@p0pr0ck5 p0pr0ck5 added pr/status/please review and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Apr 17, 2017
@p0pr0ck5 p0pr0ck5 self-assigned this Apr 20, 2017
@p0pr0ck5 p0pr0ck5 closed this Apr 21, 2017
@p0pr0ck5
Copy link
Contributor

Thanks @jdmonin, this is being merged in #2435. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants