@marinoscar/platform-infra 0.1.0-next.33 → 0.1.0-next.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +3 -1
- package/dist/fragments.d.ts.map +1 -1
- package/dist/fragments.js +1 -0
- package/dist/fragments.js.map +1 -1
- package/nginx/csp.conf +31 -0
- package/nginx/csp.dev.conf +31 -0
- package/nginx/platform/oauth-server.conf +129 -0
- package/nginx/platform/security-headers.conf +5 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @marinoscar/platform-infra
|
|
2
2
|
|
|
3
|
+
## 0.1.0-next.35
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cbf4877: OAuth server: resource-server helpers (PP-15.6). Protected resource metadata (RFC 9728) at `GET /api/oauth/.well-known/protected-resource[/<resource path>]` (`resource` is `APP_URL` plus the path, one authorization server; the bare path answers when exactly one resource is registered). `buildBearerChallenge` builds the `WWW-Authenticate: Bearer resource_metadata="..."` value with quoting and no line breaks. `JwtAuthGuard` adds that challenge to every `401` on a protected resource's routes (no credential, a bad session or PAT, an invalid or expired `oat_` token; `error="invalid_token"` only when a credential was presented); routes outside every resource and a disabled server keep their `401` exactly. `InsufficientScopeException` and `assertOAuthScopes(principal, resourceId, scopes)` answer `403` with `error="insufficient_scope"` and the granted scopes together with the missing ones; `PermissionsGuard` maps a denial of an `oauth` principal to it when the user holds the permission and a scope of the resource grants it, else a plain `403`. New in `@marinoscar/platform-api/core`: `withResponseHeaders` / `responseHeadersOf` (an exception can ask the error filter for response headers). New in `@marinoscar/platform-api/host`: `buildCorsOptions(raw, { openPaths })` (prefixes that answer any origin without credentials, through the plugin's per-request delegate; every other route keeps the policy), and `OAUTH_PUBLIC_CORS_PATHS` in `@marinoscar/platform-api/identity` for the token, register and revoke endpoints and the metadata documents. Pass it from `main.ts` when `CORS_ORIGIN` lists an allowlist. `@marinoscar/platform-infra` ships `nginx/platform/oauth-server.conf` (`/.well-known/oauth-authorization-server` and `/.well-known/oauth-protected-resource[/<path>]` to the API, `/.well-known/openid-configuration` and other unknown `/.well-known/oauth-*` paths as a JSON `404`, never the SPA); an app opts in with `include /etc/nginx/platform/oauth-server.conf;` in `infra/nginx/app.d/locations/oauth-server.conf`. Run `platform-infra sync` after upgrading.
|
|
8
|
+
- cbf4877: OAuth server gap closure (epic #1178). API: `GET /api/admin/oauth/refused-hosts` (`oauth_clients:read`) returns `[{ host, count, lastSeenAt }]` aggregated from the `oauth:client.refused` audit rows of the last 30 days, newest first, at most 100 hosts; `GET /api/admin/oauth/policy` (`oauth_clients:read`) returns `{ suggestedHosts }`, the app's `IdentityModule.forRoot({ oauthServer: { defaultAllowedClientHosts } })`. Both are served by the new `OAuthAdminHintsController`. The consent read (`GET /api/oauth/requests/:id`) adds `client.isNewToDeployment`: `true` when the client was first seen under 24 hours ago or no OTHER user holds an active grant with it (one indexed lookup, only for a client older than a day). Contract: `OAuthRefusedHost`, `OAuthPolicy` (and their schemas), `OAuthConsentRequest.client.isNewToDeployment` (required), `OAUTH_APPLICATION_TYPES`. Web: `createOAuthServerApi` gains `getPolicy()`, `/identity/headless` gains `useOAuthPolicy`, and `OAuthClientsPage` uses the API's suggested hosts when its `suggestedHosts` prop is absent (the prop still wins; a `404` from either route keeps the page working); the consent page shows its first-time notice from `isNewToDeployment` (the client-side 24-hour guess and `isNewClient` are gone). Infra: `csp.conf` and `csp.dev.conf` add `$frame_deny`, `$x_frame_options` and `$csp_header`; `platform/security-headers.conf` now sends `X-Frame-Options $x_frame_options` and `Content-Security-Policy $csp_header`, so `/oauth/consent` and `/oauth/error` answer `X-Frame-Options: DENY` and `frame-ancestors 'none'` with the rest of the policy (the app's `app.d/csp/` additions included) unchanged, and every other path is byte-for-byte as before. Run `platform-infra sync` after upgrading. TSDoc: exported OAuth symbols are documented and tagged so TypeDoc is warning-free.
|
|
9
|
+
|
|
10
|
+
## 0.1.0-next.34
|
|
11
|
+
|
|
3
12
|
## 0.1.0-next.33
|
|
4
13
|
|
|
5
14
|
## 0.1.0-next.32
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ What the package owns:
|
|
|
8
8
|
|
|
9
9
|
- the Compose files `base`, `dev`, `devdb`, `prod`, `vps` (with the stack agent), `worker`, `worker.build` and `test`, and the order Compose applies them in per mode (`composeFilesForMode()`, `dev`, `devdb`, `prod`, `vps`, `worker` and `test`, plus the modes an app adds with `registerComposeMode`), with the app's overlays last;
|
|
10
10
|
- `postgres-init/10-application-role.sh`, the executable init script `devdb` and `test` mount at `/docker-entrypoint-initdb.d`: it creates the ordinary (`NOSUPERUSER NOBYPASSRLS`) role the API runs as, so row-level security applies to it;
|
|
11
|
-
- `nginx.conf` with its include points (`app.d/http`, `server`, `locations`, `csp` and the Permissions-Policy file), the two CSP maps and the `platform/` snippets (`security-headers.conf`, `sse-proxy.conf`);
|
|
11
|
+
- `nginx.conf` with its include points (`app.d/http`, `server`, `locations`, `csp` and the Permissions-Policy file), the two CSP maps (`csp.conf`, `csp.dev.conf`; they also derive `$frame_deny`, `$x_frame_options` and `$csp_header`, so `/oauth/consent` and `/oauth/error` answer `X-Frame-Options: DENY` and `frame-ancestors 'none'` with the rest of the policy unchanged) and the `platform/` snippets (`security-headers.conf`, which sends `X-Frame-Options $x_frame_options` and `Content-Security-Policy $csp_header`, and `sse-proxy.conf`);
|
|
12
12
|
- the platform's environment variables (`env/base.env.example`) and the worker's (`env/worker.env.example`);
|
|
13
13
|
- identity rendering: the app's CLI name, env prefix, service name, worker image and test database names written into those files (`deriveInfraIdentity()`, `renderInfraText()`);
|
|
14
14
|
- the `platform-infra sync` command and its lock;
|
|
@@ -221,6 +221,8 @@ The package's own invariants also run as its tests (`docker compose config` snap
|
|
|
221
221
|
|
|
222
222
|
From the files an app copied by hand (before #714): run `npx platform-infra sync`, then move every difference from the generated files into an overlay: extra compose settings into `infra/compose/app.*.compose.yml`, nginx locations into `infra/nginx/app.d/locations/` (SSE routes through `platform/sse-proxy.conf`), the `Permissions-Policy` into `infra/nginx/app.d/permissions-policy.conf`, app variables into `infra/compose/app.env.example`. After a rename (`scripts/rename.mjs`), run the sync again: it re-renders the identity and rewrites the lock.
|
|
223
223
|
|
|
224
|
+
From a version before `$frame_deny` (the OAuth consent and error pages never framed): run `npm run platform:infra:sync` (`platform-infra sync`), then recreate nginx. `csp.conf`, `csp.dev.conf` and `platform/security-headers.conf` change together; an app that overrides one of them must take all three.
|
|
225
|
+
|
|
224
226
|
## Troubleshooting
|
|
225
227
|
|
|
226
228
|
- **`sync --check`: `differs from @marinoscar/platform-infra@…`.** A generated file was edited. Run `npm run platform:infra:sync`, then make the change in the overlay the message names.
|
package/dist/fragments.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragments.d.ts","sourceRoot":"","sources":["../src/fragments.ts"],"names":[],"mappings":"AAkBA,OAAO,EAA8B,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,kDAAkD;IAClD,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;CAC1C;AAKD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,EAAE,qBAejC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"fragments.d.ts","sourceRoot":"","sources":["../src/fragments.ts"],"names":[],"mappings":"AAkBA,OAAO,EAA8B,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,kDAAkD;IAClD,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;CAC1C;AAKD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,EAAE,qBAejC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,EAAE,qBAqB/B,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,EAAE,qBAQ7B,CAAC"}
|
package/dist/fragments.js
CHANGED
|
@@ -80,6 +80,7 @@ export const nginxInfraFragment = deepFreeze({
|
|
|
80
80
|
nginx('platform/security-headers.conf'),
|
|
81
81
|
nginx('platform/sse-proxy.conf'),
|
|
82
82
|
nginx('platform/android-app.conf'),
|
|
83
|
+
nginx('platform/oauth-server.conf'),
|
|
83
84
|
],
|
|
84
85
|
appOwnedFiles: [
|
|
85
86
|
nginx('app.d/permissions-policy.conf'),
|
package/dist/fragments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragments.js","sourceRoot":"","sources":["../src/fragments.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6DAA6D;AAC7D,gFAAgF;AAChF,EAAE;AACF,2EAA2E;AAC3E,wEAAwE;AACxE,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,EAAE;AACF,0EAA0E;AAC1E,0CAA0C;AAC1C,+DAA+D;AAC/D,yEAAyE;AACzE,uDAAuD;AACvD,qEAAqE;AACrE,gFAAgF;AAEhF,OAAO,EAAE,UAAU,EAA2C,MAAM,eAAe,CAAC;AAapF,MAAM,OAAO,GAAG,CAAC,IAAY,EAAa,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,IAAI,EAAE,EAAE,EAAE,EAAE,iBAAiB,IAAI,EAAE,EAAE,CAAC,CAAC;AACxG,MAAM,KAAK,GAAG,CAAC,IAAY,EAAa,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,IAAI,EAAE,EAAE,EAAE,EAAE,eAAe,IAAI,EAAE,EAAE,CA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B,CAAC;QAChC,KAAK,CAAC,2BAA2B,CAAC;QAClC,KAAK,CAAC,4BAA4B,CAAC;KACpC;IACD,aAAa,EAAE;QACb,KAAK,CAAC,+BAA+B,CAAC;QACtC,EAAE,GAAG,KAAK,CAAC,qBAAqB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;QAC/C,EAAE,GAAG,KAAK,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;QACjD,EAAE,GAAG,KAAK,CAAC,0BAA0B,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;QACpD,EAAE,GAAG,KAAK,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;QAC9C,KAAK,CAAC,oCAAoC,CAAC;QAC3C,KAAK,CAAC,2CAA2C,CAAC;KACnD;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA0B,UAAU,CAAC;IAChE,EAAE,EAAE,KAAK;IACT,aAAa,EAAE,6GAA6G;IAC5H,KAAK,EAAE;QACL,EAAE,IAAI,EAAE,sBAAsB,EAAE,EAAE,EAAE,4BAA4B,EAAE,MAAM,EAAE,+BAA+B,EAAE;QAC3G,EAAE,IAAI,EAAE,wBAAwB,EAAE,EAAE,EAAE,mCAAmC,EAAE;KAC5E;IACD,aAAa,EAAE,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,EAAE,EAAE,+BAA+B,EAAE,CAAC;CACtF,CAAC,CAAC"}
|
package/nginx/csp.conf
CHANGED
|
@@ -58,6 +58,37 @@ map $uri $csp_font_src_extra { include /etc/nginx/app.d/csp/font-src*.conf; }
|
|
|
58
58
|
map $uri $csp_style_src_extra { include /etc/nginx/app.d/csp/style-src*.conf; }
|
|
59
59
|
map $uri $csp_extra { include /etc/nginx/app.d/csp/extra*.conf; }
|
|
60
60
|
|
|
61
|
+
# =============================================================================
|
|
62
|
+
# Pages that must never be framed (PP-15.x: the OAuth consent and error pages)
|
|
63
|
+
# =============================================================================
|
|
64
|
+
# `/oauth/consent` and `/oauth/error` are SPA routes served by `location /` like
|
|
65
|
+
# any other. A hostile page that frames the consent screen could trick a person
|
|
66
|
+
# into clicking Allow (clickjacking), so these two answer with
|
|
67
|
+
# `X-Frame-Options: DENY` and `frame-ancestors 'none'` instead of 'self'.
|
|
68
|
+
#
|
|
69
|
+
# One variable per concern, NOT a copy of the policy: $frame_deny is 1 for those
|
|
70
|
+
# paths; $x_frame_options and $csp_header (what platform/security-headers.conf
|
|
71
|
+
# sends) derive from it, and $csp_header is the SAME policy as $csp_policy with
|
|
72
|
+
# only `frame-ancestors 'self'` rewritten, so every other directive, the app's
|
|
73
|
+
# app.d/csp/ additions included, is kept. Any other path is byte-for-byte what
|
|
74
|
+
# it was. The defence in depth is the web page's own in-frame refusal.
|
|
75
|
+
# =============================================================================
|
|
76
|
+
|
|
77
|
+
map $uri $frame_deny {
|
|
78
|
+
default 0;
|
|
79
|
+
~^/oauth/(consent|error)(/|$) 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
map $frame_deny $x_frame_options {
|
|
83
|
+
default SAMEORIGIN;
|
|
84
|
+
1 DENY;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
map "$frame_deny|$csp_policy" $csp_header {
|
|
88
|
+
"~^1\|(?<csp_head>.*)frame-ancestors 'self'(?<csp_tail>.*)$" "${csp_head}frame-ancestors 'none'${csp_tail}";
|
|
89
|
+
"~^[01]\|(?<csp_all>.*)$" $csp_all;
|
|
90
|
+
}
|
|
91
|
+
|
|
61
92
|
map $uri $csp_policy {
|
|
62
93
|
# ---------------------------------------------------------------------
|
|
63
94
|
# Default: the application itself.
|
package/nginx/csp.dev.conf
CHANGED
|
@@ -56,6 +56,37 @@ map $uri $csp_font_src_extra { include /etc/nginx/app.d/csp/font-src*.conf; }
|
|
|
56
56
|
map $uri $csp_style_src_extra { include /etc/nginx/app.d/csp/style-src*.conf; }
|
|
57
57
|
map $uri $csp_extra { include /etc/nginx/app.d/csp/extra*.conf; }
|
|
58
58
|
|
|
59
|
+
# =============================================================================
|
|
60
|
+
# Pages that must never be framed (PP-15.x: the OAuth consent and error pages)
|
|
61
|
+
# =============================================================================
|
|
62
|
+
# `/oauth/consent` and `/oauth/error` are SPA routes served by `location /` like
|
|
63
|
+
# any other. A hostile page that frames the consent screen could trick a person
|
|
64
|
+
# into clicking Allow (clickjacking), so these two answer with
|
|
65
|
+
# `X-Frame-Options: DENY` and `frame-ancestors 'none'` instead of 'self'.
|
|
66
|
+
#
|
|
67
|
+
# One variable per concern, NOT a copy of the policy: $frame_deny is 1 for those
|
|
68
|
+
# paths; $x_frame_options and $csp_header (what platform/security-headers.conf
|
|
69
|
+
# sends) derive from it, and $csp_header is the SAME policy as $csp_policy with
|
|
70
|
+
# only `frame-ancestors 'self'` rewritten, so every other directive, the app's
|
|
71
|
+
# app.d/csp/ additions included, is kept. Any other path is byte-for-byte what
|
|
72
|
+
# it was. The defence in depth is the web page's own in-frame refusal.
|
|
73
|
+
# =============================================================================
|
|
74
|
+
|
|
75
|
+
map $uri $frame_deny {
|
|
76
|
+
default 0;
|
|
77
|
+
~^/oauth/(consent|error)(/|$) 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
map $frame_deny $x_frame_options {
|
|
81
|
+
default SAMEORIGIN;
|
|
82
|
+
1 DENY;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
map "$frame_deny|$csp_policy" $csp_header {
|
|
86
|
+
"~^1\|(?<csp_head>.*)frame-ancestors 'self'(?<csp_tail>.*)$" "${csp_head}frame-ancestors 'none'${csp_tail}";
|
|
87
|
+
"~^[01]\|(?<csp_all>.*)$" $csp_all;
|
|
88
|
+
}
|
|
89
|
+
|
|
59
90
|
map $uri $csp_policy {
|
|
60
91
|
# ---------------------------------------------------------------------
|
|
61
92
|
# Default: the application, served by the Vite dev server.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# The OAuth server's well-known documents at the site root (PP-15.6)
|
|
3
|
+
# =============================================================================
|
|
4
|
+
# Include it from an app location file, app.d/locations/oauth-server.conf:
|
|
5
|
+
#
|
|
6
|
+
# include /etc/nginx/platform/oauth-server.conf;
|
|
7
|
+
#
|
|
8
|
+
# A hosted AI client (Claude, ChatGPT, an MCP inspector) discovers how to sign in
|
|
9
|
+
# from `/.well-known/...` at the ROOT of the host (RFC 8414, RFC 9728). The API owns
|
|
10
|
+
# the `/api` prefix and the documents depend on runtime settings and registered
|
|
11
|
+
# resources, so it serves them at /api/oauth/.well-known/... and this file
|
|
12
|
+
# publishes them at the root:
|
|
13
|
+
#
|
|
14
|
+
# = /.well-known/oauth-authorization-server
|
|
15
|
+
# ^~ /.well-known/oauth-authorization-server/ (path-suffixed lookups by some clients)
|
|
16
|
+
# -> /api/oauth/.well-known/authorization-server (the same document)
|
|
17
|
+
# = /.well-known/oauth-protected-resource
|
|
18
|
+
# -> /api/oauth/.well-known/protected-resource (the only resource; 404 otherwise)
|
|
19
|
+
# ^~ /.well-known/oauth-protected-resource/<path>
|
|
20
|
+
# -> /api/oauth/.well-known/protected-resource/<path>
|
|
21
|
+
# = /.well-known/openid-configuration (and the path-suffixed form)
|
|
22
|
+
# -> a JSON 404: this server is not an OpenID provider. Answered here, fast.
|
|
23
|
+
# ^~ /.well-known/oauth- (anything else of that family)
|
|
24
|
+
# -> a JSON 404
|
|
25
|
+
#
|
|
26
|
+
# JSON, NEVER THE SPA. Without these blocks every unknown /.well-known/* path
|
|
27
|
+
# falls through to `location /` and the web app answers it with index.html and a
|
|
28
|
+
# 200, which a client fails on in confusing ways. The proxied locations pass the
|
|
29
|
+
# API's own answer through, its JSON 404s included (`proxy_intercept_errors` is
|
|
30
|
+
# off), so a disabled server or an unknown resource is a JSON 404 too.
|
|
31
|
+
#
|
|
32
|
+
# Headers. The proxied locations declare no add_header, so the server-level
|
|
33
|
+
# security set (X-Content-Type-Options: nosniff and the rest) applies, and the
|
|
34
|
+
# API sets Content-Type: application/json, Cache-Control and
|
|
35
|
+
# Access-Control-Allow-Origin itself. The JSON 404 locations include
|
|
36
|
+
# platform/security-headers.conf (nginx replaces add_header, never merges) and add
|
|
37
|
+
# the wildcard CORS header, because a browser-based client reads them too.
|
|
38
|
+
# =============================================================================
|
|
39
|
+
|
|
40
|
+
location = /.well-known/oauth-authorization-server {
|
|
41
|
+
proxy_pass http://api_upstream/api/oauth/.well-known/authorization-server;
|
|
42
|
+
proxy_http_version 1.1;
|
|
43
|
+
|
|
44
|
+
proxy_set_header Host $host;
|
|
45
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
46
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
47
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
48
|
+
proxy_set_header X-Request-ID $request_id;
|
|
49
|
+
proxy_set_header Connection '';
|
|
50
|
+
|
|
51
|
+
proxy_connect_timeout 10s;
|
|
52
|
+
proxy_send_timeout 10s;
|
|
53
|
+
proxy_read_timeout 10s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
location ^~ /.well-known/oauth-authorization-server/ {
|
|
57
|
+
rewrite ^ /api/oauth/.well-known/authorization-server break;
|
|
58
|
+
proxy_pass http://api_upstream;
|
|
59
|
+
proxy_http_version 1.1;
|
|
60
|
+
|
|
61
|
+
proxy_set_header Host $host;
|
|
62
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
63
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
64
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
65
|
+
proxy_set_header X-Request-ID $request_id;
|
|
66
|
+
proxy_set_header Connection '';
|
|
67
|
+
|
|
68
|
+
proxy_connect_timeout 10s;
|
|
69
|
+
proxy_send_timeout 10s;
|
|
70
|
+
proxy_read_timeout 10s;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
location = /.well-known/oauth-protected-resource {
|
|
74
|
+
proxy_pass http://api_upstream/api/oauth/.well-known/protected-resource;
|
|
75
|
+
proxy_http_version 1.1;
|
|
76
|
+
|
|
77
|
+
proxy_set_header Host $host;
|
|
78
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
79
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
80
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
81
|
+
proxy_set_header X-Request-ID $request_id;
|
|
82
|
+
proxy_set_header Connection '';
|
|
83
|
+
|
|
84
|
+
proxy_connect_timeout 10s;
|
|
85
|
+
proxy_send_timeout 10s;
|
|
86
|
+
proxy_read_timeout 10s;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# With a URI on proxy_pass, the matched prefix (`/.well-known/oauth-protected-resource/`)
|
|
90
|
+
# is replaced by it, so `/.well-known/oauth-protected-resource/api/mcp` reaches
|
|
91
|
+
# `/api/oauth/.well-known/protected-resource/api/mcp`.
|
|
92
|
+
location ^~ /.well-known/oauth-protected-resource/ {
|
|
93
|
+
proxy_pass http://api_upstream/api/oauth/.well-known/protected-resource/;
|
|
94
|
+
proxy_http_version 1.1;
|
|
95
|
+
|
|
96
|
+
proxy_set_header Host $host;
|
|
97
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
98
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
99
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
100
|
+
proxy_set_header X-Request-ID $request_id;
|
|
101
|
+
proxy_set_header Connection '';
|
|
102
|
+
|
|
103
|
+
proxy_connect_timeout 10s;
|
|
104
|
+
proxy_send_timeout 10s;
|
|
105
|
+
proxy_read_timeout 10s;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
location = /.well-known/openid-configuration {
|
|
109
|
+
include /etc/nginx/platform/security-headers.conf;
|
|
110
|
+
add_header Access-Control-Allow-Origin "*" always;
|
|
111
|
+
default_type application/json;
|
|
112
|
+
return 404 '{"error":"not_found","error_description":"This server is not an OpenID provider; use /.well-known/oauth-authorization-server."}';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
location ^~ /.well-known/openid-configuration/ {
|
|
116
|
+
include /etc/nginx/platform/security-headers.conf;
|
|
117
|
+
add_header Access-Control-Allow-Origin "*" always;
|
|
118
|
+
default_type application/json;
|
|
119
|
+
return 404 '{"error":"not_found","error_description":"This server is not an OpenID provider; use /.well-known/oauth-authorization-server."}';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# The rest of the family (a typo, a document this server does not publish): JSON, not the SPA.
|
|
123
|
+
# Longer prefixes and the exact matches above win over this one.
|
|
124
|
+
location ^~ /.well-known/oauth- {
|
|
125
|
+
include /etc/nginx/platform/security-headers.conf;
|
|
126
|
+
add_header Access-Control-Allow-Origin "*" always;
|
|
127
|
+
default_type application/json;
|
|
128
|
+
return 404 '{"error":"not_found"}';
|
|
129
|
+
}
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
# app from then on.
|
|
15
15
|
# =============================================================================
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
# SAMEORIGIN, except DENY on the pages csp.conf lists as never framed ($frame_deny).
|
|
18
|
+
add_header X-Frame-Options $x_frame_options always;
|
|
18
19
|
add_header X-Content-Type-Options "nosniff" always;
|
|
19
20
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
20
21
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
@@ -26,9 +27,10 @@ include /etc/nginx/app.d/permissions-policy.conf;
|
|
|
26
27
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
27
28
|
|
|
28
29
|
# Content Security Policy. Per-path policy selected by the $csp_policy map in
|
|
29
|
-
# csp.conf (
|
|
30
|
+
# csp.conf ($csp_header is that policy, with frame-ancestors 'none' on the pages
|
|
31
|
+
# listed under $frame_deny) (dev.compose.yml overrides it with csp.dev.conf). worker-src and
|
|
30
32
|
# manifest-src are explicit for PWA support (issue #220): default-src 'self'
|
|
31
33
|
# covers both in spec-compliant browsers, but Safari has historically required
|
|
32
34
|
# manifest-src spelled out. See csp.conf / csp.dev.conf for the full
|
|
33
35
|
# per-policy rationale.
|
|
34
|
-
add_header Content-Security-Policy $
|
|
36
|
+
add_header Content-Security-Policy $csp_header always;
|
package/package.json
CHANGED