mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
fix(nightscout): assert the public-host floor before persisting the URL
Egress was already correct — the client fetches through safeFetch with requirePublicHost pinned off the user's opt-in, manual redirects and a timeout — but the check on the value we STORE was only a side effect of the live probe the connect route happens to run first. That makes the guard contingent on the probe's placement rather than on the input. Run isPublicUrl at input time, gated on the same self-hoster opt-in, so the URL that gets encrypted onto the row is the URL that was validated. Cover the alt-notation classes the helper knows about; each case asserts the probe was never reached, which is what distinguishes the input-time refusal from the fetch-time one.
This commit is contained in:
1 parent
0fca5ca207
commit
fd6a80a921
3 files changed
+88
-5
No files matched your search
@@ -7,11 +7,17 @@ import { z } from "zod/v4";
|
||||
* on `User` (`nightscoutUrlEncrypted` / `nightscoutTokenEncrypted`); the
|
||||
* private-host opt-in maps to `nightscoutAllowPrivateHost`.
|
||||
*
|
||||
* The URL is validated to be a parseable http(s) origin at input time. The
|
||||
* SSRF floor (public-host requirement, unless `allowPrivateHost` is set) is
|
||||
* enforced at fetch time by the client through `safeFetch` — input-shape
|
||||
* validation here only rejects garbage early so the connect route can return
|
||||
* a clear 422 instead of letting a malformed string reach the egress layer.
|
||||
* The URL is validated to be a parseable http(s) origin here. The SSRF floor
|
||||
* (public-host requirement, unless `allowPrivateHost` is set) is asserted
|
||||
* twice on purpose: the connect route runs `isPublicUrl` before it persists
|
||||
* anything, and `safeFetch` re-checks plus pins the resolved IP at connect
|
||||
* time. The shape check here only rejects garbage early so the route can
|
||||
* return a clear 422 instead of letting a malformed string reach either.
|
||||
*
|
||||
* The floor is NOT expressed as a Zod refinement because it depends on the
|
||||
* sibling `allowPrivateHost` field and needs its own error message; folding
|
||||
* it in here would collapse "malformed URL" and "private host, opt in to
|
||||
* reach it" into one opaque 422.
|
||||
*/
|
||||
export const nightscoutConnectSchema = z.object({
|
||||
// Trimmed: a trailing space / newline from a copy button reaches the
|
||||
|
||||
Reference in new issue
Block a user