-
Notifications
You must be signed in to change notification settings - Fork 283
Hide Permissions-Policy header in Nginx config to avoid duplicate #188
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
Open
dciancu
wants to merge
1
commit into
mattermost:main
Choose a base branch
from
dciancu:dciancu-patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: mattermost/docker
Length of output: 4399
🌐 Web query:
Nginx official ngx_http_headers_module add_header status codes always proxy_hide_header semantics💡 Result:
Semantics (Nginx official docs): 1) ngx_http_headers_module add_header “always” - Syntax is
add_header name value [always];andalwaysmakes the header added regardless of the response code [1]. - Withoutalways, Nginx only adds the specified header for a limited set of “success/redirect” status codes documented in the module reference [1]. 2) ngx_http_proxy_module proxy_hide_header -proxy_hide_header field;hides a response header field coming from the proxied server; by default nginx does not pass certain upstream response headers (like “Date”, “Server”, “X-Pad”, and “X-Accel-*”) andproxy_hide_headercan add additional fields to not pass [2]. - Like other list-style directives,proxy_hide_headerdirectives are inherited from a higher config level only if there are noproxy_hide_headerdirectives defined at the current level (so a location-level definition replaces the inherited list rather than extending it) [3]. 3) How they interact with “status codes” -add_headercontrols whether Nginx adds a header to the response based on the final response status, unless you usealways[1]. -proxy_hide_headercontrols whether a header from the upstream response is passed to the client at all [2]. - Therefore, if you want to guarantee a header is present/absent regardless of upstream status codes, you typically combine: a)proxy_hide_header <Header-Name>;to prevent the upstream header from being forwarded [2], and b)add_header <Header-Name> <value> always;to ensure your replacement header is added even on error responses [1]. Minimal example pattern location / { proxy_pass http://upstream; # 1) Remove upstream header proxy_hide_header X-Some-Header; # 2) Add your own header even for 4xx/5xx add_header X-Some-Header $some_value always; } Caveat about block scope - If you defineadd_headerin bothserverandlocationcontexts, the childlocationcontext configuration replaces/overrides the inherited set ofadd_headerdirectives rather than merging them (per the module’s inheritance rules) [1]. Sources: [1] nginx.org ngx_http_headers_module documentation, [2] nginx.org ngx_http_proxy_module documentation, [3] nginx trac ticket describingproxy_hide_headerredefinition/inheritance behavior.Citations:
Add
alwaysto the configured policy header.proxy_hide_headerremoves the upstream header for all response statuses. Withoutalways, Nginx does not add the replacementPermissions-Policyheader to statuses such as101or4xx/5xx. Update line 78 to useadd_header Permissions-Policy "interest-cohort=()" always;.🤖 Prompt for AI Agents