GitHubivarvong
ply
main
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});
Diagnostics6 git calls · 166 ms
CallStatusSizeTime0166 ms
discover200191 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=191 git.server.agent=git/github-9922ec520325-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=191 git.pkt.payload.max=36
ls-refs20012 KiB · 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=11990 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=152 git.pkt.data=151 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=11990 git.pkt.payload.max=122 git.ls_refs.count=151 git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.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=2 git.response.bytes=4347 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 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=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4347 git.pkt.payload.max=4247 git.sideband.band1.bytes=4247 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=4247 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400 git.pack.full=10Open pack map
fetchtree:0200919 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=919 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588 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=919 git.pkt.payload.max=892 git.sideband.band1.bytes=892 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=892 git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetchtree:02005.6 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=5724 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=tree:0 git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d 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=5724 git.pkt.payload.max=5697 git.sideband.band1.bytes=5697 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=5697 git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9bOpen pack map
fetch2001.8 KiB157 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=157 git.response.bytes=1848 git.response.cache=MISS git.response.duration_ms=157 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=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1848 git.pkt.payload.max=1821 git.sideband.band1.bytes=1821 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://github.com/ivarvong/ply
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e2ca2f4f124b67
- Request
- 4dd777e2…
- Protocol
- v2 · sha1
- Agent
- git/github-9922ec520325-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format