-
-
Notifications
You must be signed in to change notification settings - Fork 22
Add support for Cross-Origin security headers (COOP, CORP, COEP) #25
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
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.
Pull request overview
This PR adds support for three modern Cross-Origin security headers (COOP, CORP, and COEP) to the nginx security headers module, enabling cross-origin isolation capabilities required for advanced browser features like SharedArrayBuffer.
Key Changes:
- Added three new configuration directives (
security_headers_coop,security_headers_corp,security_headers_coep) with proper enum definitions and validation - Implemented header filtering logic for all three headers with appropriate default behavior (omit)
- Added comprehensive test coverage with 12 new test cases covering all possible values and combinations
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/ngx_http_security_headers_module.c |
Core implementation: added constant definitions, struct fields, configuration enums, command handlers, filter logic, and merge functions for COOP, CORP, and COEP headers |
t/headers.t |
Added 12 comprehensive test cases (TEST 12-23) covering all possible values for each header, including omit behavior and combined usage |
README.md |
Added documentation for all three new directives with syntax, defaults, context, and MDN reference links |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| switch (slcf->coop) { | ||
| case NGX_HTTP_COOP_HEADER_UNSAFE_NONE: | ||
| ngx_str_set(&val, "unsafe-none"); | ||
| break; | ||
| case NGX_HTTP_COOP_HEADER_SAME_ORIGIN_POPUPS: | ||
| ngx_str_set(&val, "same-origin-allow-popups"); | ||
| break; | ||
| case NGX_HTTP_COOP_HEADER_SAME_ORIGIN: | ||
| ngx_str_set(&val, "same-origin"); | ||
| break; | ||
| default: | ||
| val.len = 0; | ||
| val.data = NULL; | ||
| } |
Copilot
AI
Dec 27, 2025
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.
The switch statement has inconsistent indentation with extra leading spaces. This follows the pattern from the Referrer-Policy block above, but differs from the X-Frame-Options block which properly aligns the switch statement. The switch statement should be aligned at the same indentation level as the surrounding code (8 spaces from line start) rather than 12 spaces.
| switch (slcf->corp) { | ||
| case NGX_HTTP_CORP_HEADER_SAME_SITE: | ||
| ngx_str_set(&val, "same-site"); | ||
| break; | ||
| case NGX_HTTP_CORP_HEADER_SAME_ORIGIN: | ||
| ngx_str_set(&val, "same-origin"); | ||
| break; | ||
| case NGX_HTTP_CORP_HEADER_CROSS_ORIGIN: | ||
| ngx_str_set(&val, "cross-origin"); | ||
| break; | ||
| default: | ||
| val.len = 0; | ||
| val.data = NULL; | ||
| } |
Copilot
AI
Dec 27, 2025
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.
The switch statement has inconsistent indentation with extra leading spaces. This follows the pattern from the Referrer-Policy block above, but differs from the X-Frame-Options block which properly aligns the switch statement. The switch statement should be aligned at the same indentation level as the surrounding code (8 spaces from line start) rather than 12 spaces.
| switch (slcf->coep) { | ||
| case NGX_HTTP_COEP_HEADER_UNSAFE_NONE: | ||
| ngx_str_set(&val, "unsafe-none"); | ||
| break; | ||
| case NGX_HTTP_COEP_HEADER_REQUIRE_CORP: | ||
| ngx_str_set(&val, "require-corp"); | ||
| break; | ||
| default: | ||
| val.len = 0; | ||
| val.data = NULL; | ||
| } |
Copilot
AI
Dec 27, 2025
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.
The switch statement has inconsistent indentation with extra leading spaces. This follows the pattern from the Referrer-Policy block above, but differs from the X-Frame-Options block which properly aligns the switch statement. The switch statement should be aligned at the same indentation level as the surrounding code (8 spaces from line start) rather than 12 spaces.
Implements support for three additional Cross-Origin HTTP security headers as requested in #81:
New Configuration Directives
security_headers_coopsecurity_headers_coop same-origin;unsafe-none,same-origin-allow-popups,same-origin,omitomitsecurity_headers_corpsecurity_headers_corp same-origin;same-site,same-origin,cross-origin,omitomit<img>,<script>,<link>, etc.security_headers_coepsecurity_headers_coep require-corp;unsafe-none,require-corp,omitomitExample Usage
Enable cross-origin isolation for a secure application:
This configuration enables modern browser features that require cross-origin isolation while maintaining security.
Implementation Details
omitto avoid breaking existing siteshttp,server, orlocationlevel with proper inheritancesecurity_headers_xss,security_headers_frame, etc.)References
Fixes #81
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
nginx.orgwget -O - REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.