TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Common Nginx misconfigurations that leave your web server open to attack

409 pointsby sshrootover 4 years ago

15 comments

jlokierover 4 years ago
The one about proxy_pass blindly forwarding syntactically malformed requests and silently failing to process the response is astonishing.<p>It doesn&#x27;t appear to be documented. Looking through NginX documentation at <a href="http:&#x2F;&#x2F;nginx.org&#x2F;en&#x2F;docs&#x2F;http&#x2F;ngx_http_proxy_module.html" rel="nofollow">http:&#x2F;&#x2F;nginx.org&#x2F;en&#x2F;docs&#x2F;http&#x2F;ngx_http_proxy_module.html</a> I don&#x27;t see anything (e.g. under proxy_hide_header) to say it&#x27;s sometimes not applied, and there doesn&#x27;t appear to be any option to prevent this blind forwarding.<p>I would never have expected the backend to receive invalid HTTP from NginX, but more importantly it&#x27;s not uncommon for backends to send an extra header or two to tell NginX how to serve the response, with NginX removing those headers before serving.<p>How do you even handle this properly? Checking for valid HTTP might not be enough, as you need to exactly match whatever NginX&#x27;s idea of valid is, rather than matching the HTTP spec.
评论 #26266228 未加载
megousover 4 years ago
Default for root is &#x27;html&#x27; according to the docs (which is a relative path wrt &#x2F;usr&#x2F;share&#x2F;nginx), not &#x2F;etc&#x2F;nginx. <a href="http:&#x2F;&#x2F;nginx.org&#x2F;en&#x2F;docs&#x2F;http&#x2F;ngx_http_core_module.html#root" rel="nofollow">http:&#x2F;&#x2F;nginx.org&#x2F;en&#x2F;docs&#x2F;http&#x2F;ngx_http_core_module.html#root</a><p>I guess it may depend on how nginx was configured during build. But for example on Debian this is not an issue.
评论 #26263028 未加载
latchover 4 years ago
I realize that, at best, this is only tangentially related to security, but nginx&#x27;s logging is quite frustrating. It&#x27;ll log something that&#x27;s completely out of your control (like invalid SSL requests) as a [crit]<p>You end up having patterns in your log ingestion to drop errors. Or, and this is the security concern, you start to ignore nginx errors.
评论 #26261736 未加载
评论 #26261018 未加载
weinzierlover 4 years ago
A common pit I fell into is the <i>&quot;inheritance&quot;</i> of add_header. If you use <i>a single</i> add_header at a lower level <i>all</i> add_headers at the higher levels are ignored for that server or location.<p>As some headers have security implications this is an easy way to shoot yourself in the foot.<p>Another security related point is the suppression of the server version. While nginx can omit the version number out-of-the-box, you unfortunately need an extension to remove the header completely.
评论 #26261510 未加载
评论 #26262793 未加载
评论 #26262874 未加载
评论 #26261152 未加载
mjw_byrneover 4 years ago
This is a good example of the trade off between pretty&#x2F;terse&#x2F;clever and safe&#x2F;correct&#x2F;maintainable. Nginx is well-respected mature software but it&#x27;s hard to see these issues as anything other than a design blunder. The trailing-slash path traversal thing looks to me like a file system analogue of SQL injection.<p>I think d3.js is another example of this. It&#x27;s obviously written with incredible skill but I could never get on with the ultra declarative and implicit style, it always felt like a fight.<p>These days there seems to be a trend towards a verbose, explicit style, e.g. Zig (no hidden control flow - compare to C++&#x27;s operator overload-fest) and Go.
评论 #26262993 未加载
评论 #26262864 未加载
chmod775over 4 years ago
A lot of these look like not-so-great design choices in the way nginx is configured and how it handles paths.<p>Sometimes the behavior that leads to security problems here may be desirable, but it probably shouldn&#x27;t be the default.<p>For instance &quot;location &#x2F;api {&quot; probably shouldn&#x27;t match &quot;&#x2F;api..&#x2F;&quot; by default. Instead it should be treated like a file system would. The &quot;prefix&quot; matching should be a different configuration option like &quot;prefix &#x2F;api {&quot;.
评论 #26260842 未加载
评论 #26261912 未加载
评论 #26261767 未加载
评论 #26260912 未加载
polyrandover 4 years ago
I would recommend giving Caddy[0] a try.<p>Most servers&#x2F;reverse proxies need 10s of options to work <i>more or less</i> well. With Caddy, &quot;correct&quot; is the default, including having the best SSL management system (so you don&#x27;t even need certbot) I&#x27;ve seen, and using HTTPS by default. It&#x27;s true that it has some things missing (rate-limitng and weighted load balancing to name a few) that you can do in Nginx&#x2F;Traefik&#x2F;etc, but it&#x27;s 100% worth it. Caddy also has a great extension system, so those things could easily be created as extensions.<p>[0] <a href="https:&#x2F;&#x2F;caddyserver.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;caddyserver.com&#x2F;</a>
评论 #26262160 未加载
评论 #26267898 未加载
评论 #26262011 未加载
bennofsover 4 years ago
Though deprecated, <a href="https:&#x2F;&#x2F;github.com&#x2F;yandex&#x2F;gixy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;yandex&#x2F;gixy</a> is a nice checker for these kind of issues.
评论 #26273518 未加载
评论 #26261022 未加载
Kinranyover 4 years ago
Do Caddy&#x2F;Envoy have similar issues?<p>Bad UX is one of the reasons I still haven&#x27;t learned to configure Nginx :(
评论 #26261909 未加载
评论 #26261933 未加载
sharestuffover 4 years ago
There was a follow-up to this released last week by Frans Rosen on Detectify Labs that looked into middleware in general and still applicable to nginx: <a href="https:&#x2F;&#x2F;labs.detectify.com&#x2F;2021&#x2F;02&#x2F;18&#x2F;middleware-middleware-everywhere-and-lots-of-misconfigurations-to-fix&#x2F;" rel="nofollow">https:&#x2F;&#x2F;labs.detectify.com&#x2F;2021&#x2F;02&#x2F;18&#x2F;middleware-middleware-...</a>
egbertsover 4 years ago
This confabulated configuration syntax is why I discontinued using NGINX.<p>This selection of NGINX came after a frustrated debugging session of Apache .htaccess as well.<p>furthermore, unlike Apache specific IP port assignment capability, I once had to jerry-rig a dynamic configuration to tie NGINX to just one dynamic IP port out of many.<p>Sorry, I’ve gone lighttpd and haven’t looked back since.
评论 #26264456 未加载
holriover 4 years ago
Is there something similar for Apache?
jzer0coolover 4 years ago
An example of the ..&#x2F; bugs still be exploitable today.
dddwover 4 years ago
Nice overview, thanks!
nealsover 4 years ago
I&#x27;ve been running Nginx for more then 10 years now... Is there anything &quot;new&quot;? I know about serverless, but anything else that makes the webserver part easier and safe?