Artifactspublic-v0

ply

main
ply4 git calls363 ms40 KiB2 cachedprotocol v2
80 lines4.7 KiBRaw
1// The base URL's scheme (security/base-url-scheme-not-checked). ply speaks git smart HTTP and nothing else (SAFETY.md:
2// the SSH transport was removed), so a remote that is not http: or https: can never work: it is a definite bad_request
3// before any I/O, never a retry-shaped `network` and never a URL handed to a fetch implementation (Deno and Bun read
4// file: through fetch; every runtime serves data:). Redirect targets and allowUrl results were already held to http(s);
5// this holds the base to the same rule. The expectations are that rule, not ply's output.
6import { test } from 'vitest';
7import assert from 'node:assert/strict';
8import { createTransport } from '../src/http.js';
9import { listRefs } from '../src/index.js';
11const REFUSED = [
12 'file:///etc/passwd', 'data:text/plain,hi', 'blob:nodedata:abc', 'ftp://127.0.0.1/repo.git', 'ssh://git@127.0.0.1/repo.git',
13 'git://127.0.0.1/repo.git', 'git+ssh://127.0.0.1/repo.git', 'ext::sh -c "touch /tmp/pwned"', 'javascript:alert(1)',
14 'ws://127.0.0.1/repo.git', 'wss://127.0.0.1/repo.git', 'httpx://127.0.0.1/repo.git', 'about:blank',
15];
17test('a base URL that is not http: or https: is bad_request before any fetch', async () => {
18 for (const url of REFUSED) {
19 const seen = [];
20 const fetchImpl = async (u) => { seen.push(String(typeof u === 'string' ? u : u.url)); return new Response('nope', { status: 404 }); };
21 const t = createTransport(url, { fetchImpl });
22 assert.deepEqual([t.ok, t.error?.code, t.error?.what], [false, 'bad_request', 'url'], url);
23 const r = await listRefs(url, {}, { fetchImpl });
24 assert.deepEqual([r.ok, r.error?.code, r.error?.what, seen], [false, 'bad_request', 'url', []], url);
25 }
26});
28test('the refusal never repeats the URL (its userinfo is a credential)', () => {
29 const t = createTransport('ssh://git:s3cret-token@127.0.0.1/repo.git', {});
30 assert.equal(t.ok, false);
31 assert.equal(JSON.stringify(t.error).includes('s3cret-token'), false);
32 assert.equal(t.error.message.includes('127.0.0.1'), false);
33});
35test('http: and https: are accepted in any letter case (the URL parser lowercases the scheme)', () => {
36 for (const url of ['http://127.0.0.1/repo.git', 'https://127.0.0.1/repo.git', 'HTTP://127.0.0.1/repo.git', 'HtTpS://127.0.0.1/repo.git']) {
37 assert.equal(createTransport(url, {}).ok, true, url);
38 }
39});
41// The rule applies to the URL that will be requested, so allowUrl runs before it, exactly as on main. Every expected
42// value below is main's verdict (ec337c5, recorded by running these calls against that checkout) for an input the
43// scheme rule does not concern: a mapping the caller wrote, a refusal the caller wrote, and the userinfo refusal that
44// has always come first. Only a URL that would be fetched as something other than http(s) gets the new refusal.
45import { parseHttpOptions } from '../src/http.js';
46const mapToHttps = (u) => ({ ok: true, value: new URL(`https://real.example${u.pathname}`) });
47const mine = { code: 'bad_request', message: 'host not allowed', what: 'allowUrl-deny' };
48const deny = () => ({ ok: false, error: mine });
50test('an alias scheme that allowUrl maps to https is accepted: the URL requested is the https one', () => {
51 const asked = [];
52 const allowUrl = (u) => { asked.push(u.href); return mapToHttps(u); };
53 const settings = parseHttpOptions('repo://alias/team/r.git', { allowUrl });
54 assert.equal(settings.ok, true);
55 assert.equal(settings.value.url.href, 'https://real.example/team/r.git');
56 assert.deepEqual(asked, ['repo://alias/team/r.git']);
57 assert.equal(createTransport('repo://alias/team/r.git', { allowUrl: mapToHttps }).ok, true);
58});
60test('a denying allowUrl on a base that is not http(s) answers with the caller\'s own error', () => {
61 for (const url of ['file:///etc/passwd', 'ssh://git@h.example/r.git', 'repo://alias/team/r.git']) {
62 const t = createTransport(url, { allowUrl: deny });
63 assert.equal(t.ok, false, url);
64 assert.equal(t.error, mine, url);
65 }
66});
68test('a NUL, CR or LF in the userinfo of a URL that is not http(s) is the userinfo refusal, with or without allowUrl', () => {
69 for (const url of ['ssh://u%00@h.example/r.git', 'repo://u%0d@alias/r.git', 'git://u:p%0a@h.example/r.git']) {
70 for (const options of [{}, { allowUrl: deny }, { allowUrl: mapToHttps }]) {
71 const t = createTransport(url, options);
72 assert.deepEqual([t.ok, t.error?.code, t.error?.what], [false, 'bad_request', 'url userinfo'], url);
73 }
74 }
75});
77test('an allowUrl that answers with a URL that is not http(s) is refused as on main (what: allowUrl), never fetched', () => {
78 const t = createTransport('ssh://h.example/r.git', { allowUrl: (u) => ({ ok: true, value: u }) });
79 assert.deepEqual([t.ok, t.error?.code, t.error?.what], [false, 'bad_request', 'allowUrl']);
80});
Diagnostics4 git calls · 363 ms
CallStatusSizeTime0363 ms
discover200152 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=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 · hit3 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=145
git.response.cache=HIT
git.response.duration_ms=3
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 1020038 KiB · hit1 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=1
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=1
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=19912563f540228593df0c489082e5e2508e21e4
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=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2001.8 KiB359 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=359
git.response.bytes=1839
git.response.cache=MISS
git.response.duration_ms=359
git.fetch.wants=2bddbf4de07c12ee307a7fd16203756d49c84969
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=1839
git.pkt.payload.max=1818
git.sideband.band1.bytes=1817
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.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e1c332dbbb36cd
Request
e62717d8…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format