mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 13:32:28 +00:00
* ✨ Honor trusted alternate origins for backend links and OIDC Add PENPOT_TRUSTED_ORIGINS, an optional list of bare scheme://host[:port] alternate origins. A request whose Origin matches (exact, trimmed and lowercased) uses that origin as the base for links generated while serving it: emails, asset URLs, audit and webhook link fields, and redirects. Unlisted origins, requests without Origin, and background or server-to-server work keep the canonical public-uri (fail-closed). Malformed entries warn at startup and never match. Stamp the trusted origin on the request with a global http middleware that binds config public-uri for the request extent; expose the chain as root-middleware so tests assert it runs before auth and errors. Build every backend link through the canonical cf/get-public-uri. Carry the origin in the signed OIDC state (auth and organization SSO) so the callback, a navigation without Origin, re-applies it with with-public-uri for the token-exchange redirect_uri and every redirect, including logout. Verify the state token once per callback and reuse the claims; build redirect URIs with ensure-path-slash plus join and append-query-param for hash routes. A removed origin does not invalidate states signed before it (up to four hours). Bring MCP OAuth into scope: wrap its routes, stage the origin in the Redis request record at authorize time, and re-apply it in decision so issuer, resource, the approval redirect and the code-exchange iss agree on one base. Keep the log-capture watch installed while waiting for the async rejection record in the save tests; a watch removed first lost late records and read nil. Add a delayed-executor regression test that makes the race deterministic and document the rule in the backend testing memory. Closes #11625 AI-assisted-by: deepseek-v4.1-flash AI-assisted-by: qwen3.7-plus AI-assisted-by: gpt-5.6-luna AI-assisted-by: muse-spark-1.3-contributor * ✨ Serve trusted alternate origins across frontend and backend Let one installation serve a canonical domain plus trusted alternate origins, without letting request headers pick arbitrary link bases. The backend normalizes `PENPOT_TRUSTED_ORIGINS` on load: it drops malformed entries with a warning and warns about HTTP origins outside localhost. It selects the first trusted origin from `X-Penpot-Origin`, then `Origin`, and applies only scheme, host and port to the public URI, keeping the configured path. MCP OAuth keeps the canonical base because its authorize navigation has no usable origin. The frontend reads the same list from `config.js`, filled by the container entrypoint, and selects the browser origin only on an exact match. It sends `X-Penpot-Origin` on RPC calls (including GETs and multipart) and OIDC initiation, not on asset, font or external requests. SSE captures the request bindings, and export jobs store the effective base so the download link uses it after the request ends. A closed export creation schema excludes `:public-uri`, which the backend adds only after validation. Register the OIDC callback for each alias. Removing an alias does not stop already signed OIDC state, queued mail or export jobs from using it. Add regression tests across backend, frontend and the nginx entrypoint, and document the proxy setup, worker upgrade and rollback, and alias retirement. Refs #11625 AI-assisted-by: hy4-flash-free AI-assisted-by: gpt-6-luna AI-assisted-by: gpt-6.2-sol
69 lines
4.0 KiB
Clojure
69 lines
4.0 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns frontend-tests.config-test
|
|
(:require
|
|
[app.common.flags :as flags]
|
|
[app.config :as cf]
|
|
[cljs.test :as t :include-macros true]))
|
|
|
|
(def ^:private apply-devenv-defaults @#'cf/apply-devenv-defaults)
|
|
(def ^:private resolve-public-uri @#'cf/resolve-public-uri)
|
|
|
|
(t/deftest public-uri-uses-only-a-configured-alternate-origin
|
|
(let [base "https://primary.example:8443/penpot"
|
|
origins " https://other.example,\n HTTPS://Alias.Example:443 https://alias.example:9443 "
|
|
resolve (fn [origin]
|
|
(str (resolve-public-uri base origin (js/btoa origins))))]
|
|
(t/is (= "https://alias.example/penpot/" (resolve "https://alias.example")))
|
|
(t/is (= "https://alias.example:9443/penpot/" (resolve "https://alias.example:9443")))
|
|
(t/is (= "https://primary.example:8443/penpot/" (resolve "https://alias.example:8443")))
|
|
(t/is (= "https://primary.example:8443/penpot/" (resolve "https://primary.example:8443")))
|
|
(t/is (= "https://primary.example:8443/penpot/" (resolve "https://unlisted.example")))))
|
|
|
|
(t/deftest public-uri-supports-http-and-ipv6-aliases
|
|
(let [base "https://primary.example/penpot/"
|
|
origins (js/btoa "http://localhost:80 https://[::1]:9443")]
|
|
(t/is (= "http://localhost/penpot/"
|
|
(str (resolve-public-uri base "http://localhost" origins))))
|
|
(t/is (= "https://[::1]:9443/penpot/"
|
|
(str (resolve-public-uri base "https://[::1]:9443" origins))))))
|
|
|
|
(t/deftest public-uri-ignores-malformed-alternate-origins
|
|
(let [base "https://primary.example/penpot/"]
|
|
(doseq [[origin value] [["https://alias.example" "https://alias.example/"]
|
|
["https://alias.example" "https://alias.example?"]
|
|
["https://alias.example" "https://alias.example#"]
|
|
["https://alias.example" "https://user@alias.example"]
|
|
["https://alias.example" "https://alias.example:"]
|
|
["https://alias.example" "https://alias.example:65536"]
|
|
["https://alias.example" "https://*.example"]
|
|
["https://alias.example" "https://alias.example\\"]
|
|
["https://alias.example" "https://%61lias.example"]
|
|
["https://a.-example" "https://a.-example"]
|
|
["https://a.1example" "https://a.1example"]
|
|
["http://127.0.0.1" "http://127.1"]
|
|
["http://127.0.0.1" "http://0x7f000001"]]]
|
|
(t/is (= base (str (resolve-public-uri base origin (js/btoa value)))) value))
|
|
(t/is (= base (str (resolve-public-uri base "https://alias.example" "%"))))
|
|
(t/is (= base (str (resolve-public-uri base "https://alias.example" nil))))
|
|
(t/is (= "http://localhost:9001/"
|
|
(str (resolve-public-uri nil "http://localhost:9001" nil))))))
|
|
|
|
(t/deftest devenv-default-disables-admin-console
|
|
(t/testing "in devenv, without user flags, the admin-console is disabled by default"
|
|
(t/is (not (contains? (flags/parse flags/default (apply-devenv-defaults true []))
|
|
:admin-console))))
|
|
(t/testing "in devenv, the user can re-enable it with enable-admin-console"
|
|
(t/is (contains? (flags/parse flags/default (apply-devenv-defaults true [:enable-admin-console]))
|
|
:admin-console)))
|
|
(t/testing "in devenv, the user's disable-admin-console is idempotent"
|
|
(t/is (not (contains? (flags/parse flags/default (apply-devenv-defaults true [:disable-admin-console]))
|
|
:admin-console))))
|
|
(t/testing "outside devenv, no default is injected and the flags defaults apply"
|
|
(t/is (contains? (flags/parse flags/default (apply-devenv-defaults false []))
|
|
:admin-console))))
|