Skip to content

Commit 7e14582

Browse files
committed
feature: add CORS_ALLOW_PRIVATE_NETWORK_ACCESS env var
1 parent 2134898 commit 7e14582

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

common/etc/nginx/templates/gateway/cors.conf.template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set $request_cors "${request_method}_${CORS_ENABLED}";
2+
set $cors_private_network "${CORS_ALLOW_PRIVATE_NETWORK_ACCESS};
23

34
if ($request_cors = "OPTIONS_1") {
45
add_header 'Access-Control-Allow-Origin' '${CORS_ALLOWED_ORIGIN}';
@@ -11,6 +12,18 @@ if ($request_cors = "OPTIONS_1") {
1112
# Tell client that this pre-flight info is valid for 20 days
1213
#
1314
add_header 'Access-Control-Max-Age' 1728000;
15+
#
16+
# Allow/deny Private Network Access CORS requests.
17+
# https://developer.chrome.com/blog/private-network-access-preflight/
18+
#
19+
if ($http_access_control_request_private_network = "true") {
20+
if ($cors_private_network = "true") {
21+
add_header 'Access-Control-Allow-Private-Network' 'true';
22+
}
23+
if ($cors_private_network = "false") {
24+
add_header 'Access-Control-Allow-Private-Network' 'false';
25+
}
26+
}
1427
add_header 'Content-Type' 'text/plain; charset=utf-8';
1528
add_header 'Content-Length' 0;
1629
return 204;

docs/getting_started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ running as a Container or as a Systemd service.
4040
| `HEADER_PREFIXES_TO_STRIP` | No | | | A list of HTTP header prefixes that exclude headers client responses. List should be specified in lower-case and a semicolon (;) should be used to as a deliminator between values. For example: `x-goog-;x-something-` |
4141
| `CORS_ENABLED` | No | `true`, `false` | `false` | Flag that enables CORS headers on GET requests and enables pre-flight OPTIONS requests. If enabled, this will add CORS headers for "fully open" cross domain requests by default, meaning all domains are allowed, similar to the settings show in [this example](https://enable-cors.org/server_nginx.html). CORS settings can be fine-tuned by overwriting the [`cors.conf.template`](/common/etc/nginx/templates/gateway/cors.conf.template) file. |
4242
| `CORS_ALLOWED_ORIGIN` | No | | | value to set to be returned from the CORS `Access-Control-Allow-Origin` header. This value is only used if CORS is enabled. (default: \*) |
43+
| `CORS_ALLOW_PRIVATE_NETWORK_ACCESS` | No | `true`, `false` | | Flag that enables responding to the CORS OPTIONS pre-flight request header `Access-Control-Request-Private-Network` with the `Access-Control-Allow-Private-Network` header. If the value is "true", responds with "true", if "false" responds with "false. If the environment variable is blank/not set, does not respond with any header. This value is only used if CORS is enabled. See [Private Network Access: introducing preflights](https://developer.chrome.com/blog/private-network-access-preflight/) for more information about this header. |
4344

4445

4546
If you are using [AWS instance profile credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html),

0 commit comments

Comments
 (0)