Repository navigation
feat(domains): Set response streaming, headers, redirects and access limits - #122
Conversation
…limits The domain form now sets streaming responses, custom response headers, a redirect from aliases to the primary domain, a username and password, and an IP allow-list, which before needed hand edits to the proxy config. Saved users are sent back by name only, so editing a domain keeps their passwords without the form ever holding the stored hashes. Values the proxy would reject are flagged in the form before saving.
Code Review SummaryThe domain form gains sections for response streaming, added response headers, basic auth and an IP allow-list, plus an alias-to-primary redirect toggle that only appears when aliases exist. Every new field is validated client-side before save, so malformed header names, duplicate headers or usernames, bad IPv4/IPv6 or CIDR entries and password-less new users prevent submission. Saved basic-auth users come back by username only, so stored hashes never reach the form and an empty password preserves the stored one. 🚀 Key Improvements
💡 Minor Suggestions
|
| .filter(Boolean); | ||
| } | ||
|
|
||
| const allowIPsError = computed(() => { |
There was a problem hiding this comment.
The pattern matches any hex-ish string, so 999.999.999.999, cafe, 1.2.3.4.5 or 10.0.0.0/999 pass validation and are saved into the proxy's allow-list, where nginx then refuses the config. Validate IPv4 octets and CIDR prefix ranges (and bound IPv6) instead of accepting [0-9A-Fa-f:.]+.
| const allowIPsError = computed(() => { | |
| const IPV4_OR_CIDR = | |
| /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\/(?:3[0-2]|[12]?\d))?$/; | |
| const IPV6_OR_CIDR = /^(?:[0-9A-Fa-f]{0,4}:){2,7}[0-9A-Fa-f]{0,4}(?:\/(?:12[0-8]|1[01]\d|[1-9]?\d))?$/; | |
| const allowIPsError = computed(() => { | |
| const bad = allowIPs().find((entry) => !IPV4_OR_CIDR.test(entry) && !IPV6_OR_CIDR.test(entry)); | |
| return bad ? `${bad} is not an IP address or CIDR range.` : ""; | |
| }); |
| return ""; | ||
| }); | ||
|
|
||
| const headersError = computed(() => { |
There was a problem hiding this comment.
Two rows with the same header name both validate, but responseHeaders() builds a Record, so Object.fromEntries keeps only the last one and silently drops the other. Reject duplicates here, as basicAuthError already does for usernames.
| const headersError = computed(() => { | |
| const headersError = computed(() => { | |
| const seen = new Set<string>(); | |
| for (const header of form.value.headers) { | |
| if (!header.name && !header.value) continue; | |
| if (!/^[A-Za-z0-9-]{1,64}$/.test(header.name)) return "Header names may contain only letters, digits and dashes."; | |
| if (header.value.includes("$")) return `${header.name} cannot contain $.`; | |
| const key = header.name.toLowerCase(); | |
| if (seen.has(key)) return `${header.name} is listed twice.`; | |
| seen.add(key); | |
| } | |
| return ""; | |
| }); |
| proxy_timeout: form.value.proxy_timeout || undefined, | ||
| proxy_buffering: form.value.stream_responses ? false : undefined, | ||
| response_headers: responseHeaders(), | ||
| canonical_redirect: form.value.canonical_redirect ? "primary" : undefined, |
There was a problem hiding this comment.
The checkbox is hidden when no alias remains, but form.canonical_redirect keeps its value, so saving a domain whose aliases were all removed still writes canonical_redirect: "primary". Guard the payload with the same alias condition the v-if uses, otherwise the redirect silently applies when an alias is added later.
| canonical_redirect: form.value.canonical_redirect ? "primary" : undefined, | |
| canonical_redirect: | |
| form.value.canonical_redirect && form.value.aliases.some((a) => a.trim()) ? "primary" : undefined, |
The allow-list refuses addresses with out-of-range parts or prefixes before the agent sees them, a header listed twice is refused instead of one copy being dropped, and removing every alias also turns off the alias redirect.
Deploying flatrun-ui with
|
| Latest commit: |
4eb91ab
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://943f8f97.flatrun-ui.pages.dev |
| Branch Preview URL: | https://feat-proxy-tuning.flatrun-ui.pages.dev |
| const IPV4 = new RegExp(`^${IPV4_OCTET}(\\.${IPV4_OCTET}){3}(\\/(3[0-2]|[12]?\\d))?$`); | ||
| const IPV6 = /^[0-9A-Fa-f:]*:[0-9A-Fa-f:]*(\/(12[0-8]|1[01]\d|[1-9]?\d))?$/; | ||
|
|
||
| function validIPv6(entry: string) { |
There was a problem hiding this comment.
filter(Boolean) hides empty groups, so malformed addresses such as :1:2:3:4:5:6:7:8 and ::: pass validIPv6 and are written into the allow-list, where nginx refuses the whole site config. Split on :: and validate every group instead of dropping empty ones.
| function validIPv6(entry: string) { | |
| function validIPv6(entry: string) { | |
| if (!IPV6.test(entry)) return false; | |
| const address = entry.split("/")[0]; | |
| const parts = address.split("::"); | |
| if (parts.length > 2) return false; | |
| const sides = parts.map((part) => (part === "" ? [] : part.split(":"))); | |
| if (sides.some((side) => side.some((group) => !/^[0-9A-Fa-f]{1,4}$/.test(group)))) return false; | |
| const groups = sides.reduce((count, side) => count + side.length, 0); | |
| return parts.length === 2 ? groups <= 7 : groups === 8; | |
| } |
Add streaming, response headers, the alias redirect, basic auth and the IP allow-list to the domain form. Saved users come back by name only, so the form never holds the stored hashes.