GitLabgitlab-org

cli

main
ply7 git calls206 ms97 KiB5 cachedprotocol v2
104 lines3.1 KiBRaw
1package gomodproxy
3import (
4 "fmt"
5 "net/http"
6 "strconv"
7 "strings"
8 "unicode"
9 "unicode/utf8"
11 "gitlab.com/gitlab-org/cli/internal/text"
14const firewallHeader = "X-Gitlab-Dependency-Firewall"
16// cmd/go/internal/web shows a proxy's error body only under these
17// constraints; violating any leaves the user a bare "403 Forbidden":
18//
19// - the media type must be text/plain with charset utf-8, us-ascii, or
20// absent;
21// - the detail is truncated at 8 lines and 648 bytes, counted with the
22// lines rejoined by "\n\t", and a line that would overflow is dropped
23// whole;
24// - it stops at the first blank line;
25// - any rune that is neither graphic nor space (a control or format
26// character such as U+200B) voids the whole detail.
27const (
28 maxDetailLines = 8
29 maxDetailBytes = 8 * 81
30 blockedValue = "blocked"
33// writeBlocked answers 403 deliberately: cmd/go treats only 404 and 410 as
34// "not on this proxy, try the next source", so a 404 would let go fetch the
35// blocked module elsewhere; every other non-200 is terminal.
36func writeBlocked(w http.ResponseWriter, modulePath, version, reason string) {
37 body := blockBody(modulePath, version, reason)
38 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
39 w.Header().Set(firewallHeader, blockedValue)
40 w.Header().Set("Cache-Control", "no-store")
41 w.Header().Set("Content-Length", strconv.Itoa(len(body)))
42 w.WriteHeader(http.StatusForbidden)
43 _, _ = w.Write([]byte(body))
46func blockBody(modulePath, version, reason string) string {
47 lines := []string{
48 fmt.Sprintf("blocked by the GitLab Dependency Firewall: %s@%s", modulePath, version),
49 }
50 if r := sanitizeReason(reason); r != "" {
51 lines = append(lines, "reason: "+r)
52 }
53 return truncateDetail(lines)
56// sanitizeReason flattens server-supplied text onto one line: a blank line
57// would cut the detail short, and a rune go doesn't accept would void it.
58func sanitizeReason(reason string) string {
59 stripped := text.Strip(reason)
60 cleaned := strings.Map(func(r rune) rune {
61 if r == utf8.RuneError || unicode.IsControl(r) || unicode.IsSpace(r) {
62 return ' '
63 }
64 if !unicode.IsGraphic(r) {
65 return -1
66 }
67 return r
68 }, stripped)
69 return strings.Join(strings.Fields(cleaned), " ")
72// truncateDetail budgets each line against go's "\n\t" rendering. Trimming
73// the body to 648 bytes with "\n" breaks comes out over budget once go
74// rejoins it, and go then drops the whole reason line; cutting the
75// overflowing line here, on a rune boundary, keeps it readable.
76func truncateDetail(lines []string) string {
77 const ellipsis = "…"
78 if len(lines) > maxDetailLines {
79 lines = lines[:maxDetailLines]
80 }
81 used := 0
82 kept := make([]string, 0, len(lines))
83 for i, line := range lines {
84 if i > 0 {
85 used += len("\n\t")
86 }
87 room := maxDetailBytes - used
88 if len(line) <= room {
89 used += len(line)
90 kept = append(kept, line)
91 continue
92 }
93 if room > len(ellipsis) {
94 // An invalid UTF-8 tail would void the whole detail.
95 line = line[:room-len(ellipsis)]
96 for !utf8.ValidString(line) {
97 line = line[:len(line)-1]
98 }
99 kept = append(kept, line+ellipsis)
100 }
101 break
102 }
103 return strings.Join(kept, "\n")
Diagnostics7 git calls · 206 ms
CallStatusSizeTime0206 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0200361 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=361
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=506cba622ceda1473ee3cde63969809c144b7247
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=361
git.pkt.payload.max=334
git.sideband.band1.bytes=334
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=334
git.pack.trailer=26d32585a3a474717e00a318584ccd16918c9d32
Open pack map
fetchtree:0200379 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=379
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=21702eb6df99111b4d7a039e655c720d4209d5b6
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=379
git.pkt.payload.max=352
git.sideband.band1.bytes=352
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=352
git.pack.trailer=7d54607262a7ed73d2686c4df38d0272960c21fc
Open pack map
fetch2001.5 KiB196 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=196
git.response.bytes=1564
git.response.cache=MISS
git.response.duration_ms=196
git.fetch.wants=6572e89f0ea40f6063f4a776497deb2d81d33517
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1564
git.pkt.payload.max=1537
git.sideband.band1.bytes=1537
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e25a1b6f96a23e
Request
05f9acf1…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format