main
ply4 git calls30 ms42 KiB3 cachedprotocol v2
80 lines3.1 KiBRaw
1// Path checks that run on the raw request string, before URL normalization collapses `.` and `..`.
2// `%2e` / `%2f` / `%5c` are rejected as sequences, not only after they decode into a separator.
4import { atIndex } from './absent.ts';
5import { unwrapOr } from './option.ts';
7/** Path and query are split off a raw URL or an already-relative path. No URL parser. */
8export function extractRequestPath(raw: string): string {
9 let rest = raw.trim();
10 const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(rest);
11 if (scheme) {
12 rest = rest.slice(scheme[0].length);
13 const slash = rest.indexOf('/');
14 rest = slash < 0 ? '/' : rest.slice(slash);
15 }
16 const hash = rest.indexOf('#');
17 if (hash >= 0) rest = rest.slice(0, hash);
18 const query = rest.indexOf('?');
19 if (query >= 0) rest = rest.slice(0, query);
20 return rest;
23function encodedSeparator(value: string): boolean {
24 return /%2e|%2f|%5c/i.test(value);
27/** True when a raw path contains `.`, `..`, a backslash, or an encoded form of those. */
28export function rawPathHasUnsafeSegment(path: string): boolean {
29 if (path.includes('\\') || encodedSeparator(path)) return true;
30 const segments = path.split('/');
31 for (let i = 0; i < segments.length; i++) {
32 const segment = unwrapOr(atIndex(segments, i), '');
33 const edge = i === 0 || i === segments.length - 1;
34 if (segment === '') {
35 if (!edge) return true;
36 continue;
37 }
38 if (segment === '.' || segment === '..') return true;
39 let current = segment;
40 for (let pass = 0; pass < 3; pass++) {
41 if (encodedSeparator(current) || current.includes('\\')) return true;
42 let decoded: string;
43 try { decoded = decodeURIComponent(current); }
44 catch { return true; }
45 if (decoded === '.' || decoded === '..' || decoded.includes('/') || decoded.includes('\\') || decoded.includes('\0')) return true;
46 if (decoded === current) break;
47 current = decoded;
48 }
49 }
50 return false;
53/**
54 * The `path` query value is a git path. Reject encoded separators and dot segments in the raw
55 * query, before searchParams decodes them.
56 */
57export function rawQueryPathUnsafe(raw: string): boolean {
58 const qIndex = raw.indexOf('?');
59 if (qIndex < 0) return false;
60 let query = raw.slice(qIndex + 1);
61 const hash = query.indexOf('#');
62 if (hash >= 0) query = query.slice(0, hash);
63 for (const pair of query.split('&')) {
64 const eq = pair.indexOf('=');
65 const key = eq < 0 ? pair : pair.slice(0, eq);
66 if (key !== 'path') continue;
67 const value = eq < 0 ? '' : pair.slice(eq + 1);
68 // `%2F` is a path separator inside a git path and is what URLSearchParams writes for `/`, so it is allowed here;
69 // an encoded dot or backslash is not. The decoded value is then checked segment by segment.
70 if (value.includes('\\') || /%2e|%5c/i.test(value)) return true;
71 let decoded: string;
72 try { decoded = decodeURIComponent(value.replace(/\+/g, '%20')); }
73 catch { return true; }
74 if (decoded.includes('\\') || decoded.includes('\0')) return true;
75 for (const segment of decoded.split('/')) {
76 if (segment === '.' || segment === '..') return true;
77 }
78 }
79 return false;
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 ms
discover200152 B4 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit4 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=4
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=23
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2001.2 KiB · hit23 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1249
git.response.cache=HIT
git.response.duration_ms=23
git.fetch.wants=02f0b69ba85b94200c376e4865a8485692bd21a5
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=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1249
git.pkt.payload.max=1228
git.sideband.band1.bytes=1227
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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e2bd7b2865cfc3
Request
718cc83c…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format