Skip to content

Conversation

Copy link

Copilot AI commented Sep 30, 2025

Implements support for three additional Cross-Origin HTTP security headers as requested in #81:

  • Cross-Origin-Opener-Policy (COOP) - Controls whether a document can share a browsing context group with cross-origin documents
  • Cross-Origin-Resource-Policy (CORP) - Controls which origins can load the resource
  • Cross-Origin-Embedder-Policy (COEP) - Prevents loading cross-origin resources without explicit permission

New Configuration Directives

security_headers_coop

security_headers_coop same-origin;
  • Values: unsafe-none, same-origin-allow-popups, same-origin, omit
  • Default: omit
  • Ensures top-level documents don't share browsing context with cross-origin documents
  • Required for enabling powerful browser features like SharedArrayBuffer

security_headers_corp

security_headers_corp same-origin;
  • Values: same-site, same-origin, cross-origin, omit
  • Default: omit
  • Controls which origins can load the resource via <img>, <script>, <link>, etc.

security_headers_coep

security_headers_coep require-corp;
  • Values: unsafe-none, require-corp, omit
  • Default: omit
  • Prevents loading cross-origin resources without explicit CORP permission
  • Works with COOP to enable cross-origin isolation

Example Usage

Enable cross-origin isolation for a secure application:

server {
    listen 443 ssl;
    server_name app.example.com;
    
    security_headers on;
    security_headers_coop same-origin;
    security_headers_corp same-origin;
    security_headers_coep require-corp;
    
    location / {
        # Your application
    }
}

This configuration enables modern browser features that require cross-origin isolation while maintaining security.

Implementation Details

  • All three headers default to omit to avoid breaking existing sites
  • Can be configured at http, server, or location level with proper inheritance
  • Follows the same pattern as existing headers (security_headers_xss, security_headers_frame, etc.)
  • Comprehensive test coverage with 12 new tests
  • Complete documentation in README

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.org
    • Triggering command: wget -O - REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Feature Request: Additional Cross-Origin headers (COOP CORP, COEP)</issue_title>
<issue_description>Implement new upcoming HTTP Cross-Origin headers.

Sources:

Comments on the Issue (you are @copilot in this section)

Fixes #17

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
Copilot AI changed the title [WIP] Feature Request: Additional Cross-Origin headers (COOP CORP, COEP) Add support for Cross-Origin security headers (COOP, CORP, COEP) Sep 30, 2025
Copilot AI requested a review from dvershinin September 30, 2025 15:01
@dvershinin dvershinin requested a review from Copilot December 27, 2025 01:32
Copy link

Copilot AI left a 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.

Comment on lines +462 to +475
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;
}
Copy link

Copilot AI Dec 27, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +486 to +499
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;
}
Copy link

Copilot AI Dec 27, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +510 to +520
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;
}
Copy link

Copilot AI Dec 27, 2025

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.

Copilot uses AI. Check for mistakes.
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.

Feature Request: Additional Cross-Origin headers (COOP CORP, COEP)

2 participants