GitLabgitlab-org

cli

main
ply7 git calls360 ms98 KiB4 cachedprotocol v2
88 lines3.1 KiBRaw
1package proxy
3import (
4 "encoding/json"
5 "fmt"
6 "html"
7 "strconv"
8 "strings"
9 "unicode/utf8"
11 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/policy"
12 "gitlab.com/gitlab-org/cli/internal/text"
15// firewallHeader is the response header the proxy sets on a synthesized
16// block. It is also the request header the proxy injects on allowed
17// upstream traffic (value "allowed" or a decision ID).
18const firewallHeader = "X-Gitlab-Dependency-Firewall"
20// checkFailedReason replaces a failed policy check's reason, which is the raw
21// API error with its URLs and server text, in the response the package
22// manager prints.
23const checkFailedReason = "Dependency Firewall could not evaluate this package"
25// maxBlockReasonPhrase caps the status line's reason phrase in bytes; the
26// body still carries the full reason.
27const maxBlockReasonPhrase = 512
29// blockResponse returns a complete raw HTTP/1.1 403 response for a tunnelled
30// HTTPS request, shaped like the given ecosystem's native registry error so
31// the package manager renders a clean message. The reason is in the body and,
32// because Maven, Gradle and pip print the status line rather than the body,
33// in the reason phrase too. Plain-HTTP blocks go through net/http, which
34// always writes "Forbidden".
35func blockResponse(ecosystem, reason string, checkFailed bool) string {
36 contentType, body := blockBody(ecosystem, reason)
37 var b strings.Builder
38 b.WriteString("HTTP/1.1 403 " + blockReasonPhrase(reason, checkFailed) + "\r\n")
39 b.WriteString("Content-Type: " + contentType + "\r\n")
40 b.WriteString(firewallHeader + ": blocked\r\n")
41 b.WriteString("Content-Length: " + strconv.Itoa(len(body)) + "\r\n")
42 b.WriteString("Connection: close\r\n")
43 b.WriteString("\r\n")
44 b.WriteString(body)
45 return b.String()
48// blockReasonPhrase is a single-line reason phrase: the reason comes from the
49// policy, so a CR or LF in it must not end the status line.
50func blockReasonPhrase(reason string, checkFailed bool) string {
51 phrase := "Blocked by GitLab Dependency Firewall"
52 switch {
53 case checkFailed && strings.HasPrefix(reason, policy.InternalErrorPhrasePrefix):
54 phrase = text.SanitizeInline(reason)
55 case checkFailed:
56 // A failed check's reason can be the raw API error.
57 return checkFailedReason
58 default:
59 if r := text.SanitizeInline(reason); r != "" {
60 phrase += ": " + r
61 }
62 }
63 if len(phrase) <= maxBlockReasonPhrase {
64 return phrase
65 }
66 end := maxBlockReasonPhrase
67 for end > 0 && !utf8.RuneStart(phrase[end]) {
68 end--
69 }
70 return phrase[:end]
73// blockBody returns the Content-Type and body bytes for an ecosystem-native
74// 403 error carrying reason.
75func blockBody(ecosystem, reason string) (string, string) {
76 switch ecosystem {
77 case "npm", "nuget":
78 //nolint:forbidigo // serializing a small error body for an HTTP response, not stdout
79 payload, _ := json.Marshal(map[string]string{"error": reason})
80 return "application/json", string(payload)
81 case "pypi", "maven":
82 return "text/html", fmt.Sprintf("<h1>403 Forbidden</h1><p>%s</p>", html.EscapeString(reason))
83 case "gem":
84 return "text/plain", reason
85 default:
86 return "text/plain", reason
87 }
Diagnostics7 git calls · 360 ms
CallStatusSizeTime0360 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
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 KiB3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=3
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 · 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=32926
git.response.cache=HIT
git.response.duration_ms=3
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 · 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=361
git.response.cache=HIT
git.response.duration_ms=3
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:02001.0 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=1051
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=7a2a90605315ba5b37f63c08726e6b2caa26e48d
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=1051
git.pkt.payload.max=1024
git.sideband.band1.bytes=1024
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1024
git.pack.trailer=7503ef36a75d3595b473035c69e639fd0ce41598
Open pack map
fetch2001.4 KiB348 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=348
git.response.bytes=1413
git.response.cache=MISS
git.response.duration_ms=348
git.fetch.wants=2f82e51e23b33a64c0fac99c8920f3e6d15f3b87
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=1413
git.pkt.payload.max=1386
git.sideband.band1.bytes=1386
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
a5e20da5c8f97f3b
Request
cfbf571a…
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