detached 66e4d1b

fix: address CodeRabbit review feedback

- Rename unused trustedNets param to _ in ProxyCIDRAllowlist with doc comment
- Use consistent JSON error responses in proxy CIDR allowlist (matching registry)
commit
66e4d1be508196e65c26311976aa7b8d553a7b72
author
bnema · · 2026-03-27 22:16 UTC
parent
bcbd4d9
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +9 -3
M internal/adapters/in/http/middleware/cidr.go +6 -2
@@ -54,7 +54,9 @@ func RegistryCIDRAllowlist(allowedNets, trustedNets []*net.IPNet, log zerowrap.L
5454 // This is used to ensure only trusted sources (e.g. Cloudflare edge IPs) can reach the
5555 // proxy server, preventing direct-to-origin attacks that bypass CDN protections.
5656 // An empty allowedNets slice is a no-op (all traffic passes through).
57-func ProxyCIDRAllowlist(allowedNets, trustedNets []*net.IPNet, log zerowrap.Logger) func(http.Handler) http.Handler {
57+// Note: the second parameter is accepted for signature consistency with RegistryCIDRAllowlist
58+// but is intentionally unused — this middleware validates the direct network peer, not forwarded IPs.
59+func ProxyCIDRAllowlist(allowedNets, _ []*net.IPNet, log zerowrap.Logger) func(http.Handler) http.Handler {
5860 return func(next http.Handler) http.Handler {
5961 if len(allowedNets) == 0 {
6062 return next
@@ -86,7 +88,9 @@ func ProxyCIDRAllowlist(allowedNets, trustedNets []*net.IPNet, log zerowrap.Logg
8688 Str(zerowrap.FieldClientIP, remoteIP).
8789 Msg("proxy access denied by origin IP allowlist")
8890
89- http.Error(w, "Forbidden", http.StatusForbidden)
91+ w.Header().Set("Content-Type", "application/json")
92+ w.WriteHeader(http.StatusForbidden)
93+ _ = json.NewEncoder(w).Encode(dto.ErrorResponse{Error: "Forbidden"})
9094 })
9195 }
9296 }
@@ -54,7 +54,9 @@ func RegistryCIDRAllowlist(allowedNets, trustedNets []*net.IPNet, log zerowrap.L
54 // This is used to ensure only trusted sources (e.g. Cloudflare edge IPs) can reach the54 // This is used to ensure only trusted sources (e.g. Cloudflare edge IPs) can reach the
55 // proxy server, preventing direct-to-origin attacks that bypass CDN protections.55 // proxy server, preventing direct-to-origin attacks that bypass CDN protections.
56 // An empty allowedNets slice is a no-op (all traffic passes through).56 // An empty allowedNets slice is a no-op (all traffic passes through).
57-func ProxyCIDRAllowlist(allowedNets, trustedNets []*net.IPNet, log zerowrap.Logger) func(http.Handler) http.Handler {57+// Note: the second parameter is accepted for signature consistency with RegistryCIDRAllowlist
58+// but is intentionally unused — this middleware validates the direct network peer, not forwarded IPs.
59+func ProxyCIDRAllowlist(allowedNets, _ []*net.IPNet, log zerowrap.Logger) func(http.Handler) http.Handler {
58 return func(next http.Handler) http.Handler {60 return func(next http.Handler) http.Handler {
59 if len(allowedNets) == 0 {61 if len(allowedNets) == 0 {
60 return next62 return next
@@ -86,7 +88,9 @@ func ProxyCIDRAllowlist(allowedNets, trustedNets []*net.IPNet, log zerowrap.Logg
86 Str(zerowrap.FieldClientIP, remoteIP).88 Str(zerowrap.FieldClientIP, remoteIP).
87 Msg("proxy access denied by origin IP allowlist")89 Msg("proxy access denied by origin IP allowlist")
88 90
89- http.Error(w, "Forbidden", http.StatusForbidden)91+ w.Header().Set("Content-Type", "application/json")
92+ w.WriteHeader(http.StatusForbidden)
93+ _ = json.NewEncoder(w).Encode(dto.ErrorResponse{Error: "Forbidden"})
90 })94 })
91 }95 }
92 }96 }
M internal/app/run.go +3 -1
@@ -1805,7 +1805,9 @@ func buildProxyCIDRAllowlistMiddleware(cfg Config, trustedNets []*net.IPNet, log
18051805 Str("host", r.Host).
18061806 Str(zerowrap.FieldClientIP, middleware.GetClientIP(r, trustedNets)).
18071807 Msg("proxy access denied due to invalid proxy_allowed_ips configuration")
1808- http.Error(w, "Forbidden", http.StatusForbidden)
1808+ w.Header().Set("Content-Type", "application/json")
1809+ w.WriteHeader(http.StatusForbidden)
1810+ _ = json.NewEncoder(w).Encode(dto.ErrorResponse{Error: "Forbidden"})
18091811 })
18101812 }
18111813 }
@@ -1805,7 +1805,9 @@ func buildProxyCIDRAllowlistMiddleware(cfg Config, trustedNets []*net.IPNet, log
1805 Str("host", r.Host).1805 Str("host", r.Host).
1806 Str(zerowrap.FieldClientIP, middleware.GetClientIP(r, trustedNets)).1806 Str(zerowrap.FieldClientIP, middleware.GetClientIP(r, trustedNets)).
1807 Msg("proxy access denied due to invalid proxy_allowed_ips configuration")1807 Msg("proxy access denied due to invalid proxy_allowed_ips configuration")
1808- http.Error(w, "Forbidden", http.StatusForbidden)1808+ w.Header().Set("Content-Type", "application/json")
1809+ w.WriteHeader(http.StatusForbidden)
1810+ _ = json.NewEncoder(w).Encode(dto.ErrorResponse{Error: "Forbidden"})
1809 })1811 })
1810 }1812 }
1811 }1813 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close