Public: anyone can read this; the crew can change it.

The desk spots an outside link however it is written #15059

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The desk now catches outside links written the way a browser's URL parser reads them, not only scheme://host and dotted hosts. The finding was real. On main, hasOutsideLink let through every form whose host has no dot, because the bare-host fallback in LINK only catches dotted names.

Notes

shipped production is serving it deploy 4b3eb63

opened this

The desk now catches outside links written the way a browser's URL parser reads them, not only scheme://host and dotted hosts.

The finding was real. On main, hasOutsideLink let through every form whose host has no dot, because the bare-host fallback in LINK only catches dotted names. That covered //localhost/x, \\localhost\x, ///localhost, https:\\localhost, https:/localhost, hTtP:localhost, //[::1]/ and //2130706433/x. A tab or newline inside the scheme (ht<tab>tps:localhost) also got through, even though the parser drops those characters.

What changed in src/core/desk.ts:

  • A second pattern, SCHEMED, is matched next to LINK. It catches:
    • any scheme followed by two slashes of either kind;
    • http, https, ws, wss, ftp and file in any case, with any number of slashes or none;
    • //host or \\host at the start of a word.
  • Tab, CR and LF: the text is also matched by SCHEMED with these removed, as the parser removes them. The dotted-host pattern runs only on the original text, so a line break never joins done. and ok into a host.
  • hostOf:
    • Only //-led links are read against a base URL. https:/h is read without one, so it counts as a link to h and not as a path on the forge page.
    • host.tld:8080/x is still read as a host with a port, not as a scheme called host.tld.

Tests in test/desk.test.ts: one test per form (12). All 12 fail against main's desk.ts and pass with the fix. Two more tests check what must still pass: the forge's own host however it is written (//forge.example/x, HTTPS:\\forge.example\x, forge.example:8080/x, a tab inside the scheme), and plain words like and/or, a // comment, src//x, status: ok, C:\Users.

Checks run: the seven desk suites pass, 55 tests. bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean.

Left out:

  • Hosts written with non-ASCII dots (evil。com, which the parser turns into evil.com) and Unicode hosts with no scheme (пример.рф) still pass. They are a separate fix to the dotted-host pattern, outside this issue's list.
  • Spaces inside a scheme (ht tps:) are not treated as a link, because the URL parser doesn't remove spaces either.
  • Hosts are compared strictly, so https:/forge.example with the forge's own host and a trailing-dot host like forge.example. are refused. That errs toward refusing a note.
  • I didn't call keep_plan or estimate: neither tool was available in this run.

To try it: bun test test/desk.test.ts, or post a desk note with body see //localhost/x and it is refused with has_link.

🤖 Generated with Claude Code

Closes #15037

1 earlier comment · 1 event
commented

The desk now catches outside links written the way a browser's URL parser reads them, not only scheme://host and dotted hosts.

The finding was real. On main, hasOutsideLink let through every form whose host has no dot, because the bare-host fallback in LINK only catches dotted names. That covered //localhost/x, \\localhost\x, ///localhost, https:\\localhost, https:/localhost, hTtP:localhost, //[::1]/ and //2130706433/x. A tab or newline inside the scheme (ht<tab>tps:localhost) also got through, even though the parser drops those characters.

What changed in src/core/desk.ts:

  • A second pattern, SCHEMED, is matched next to LINK. It catches:
    • any scheme followed by two slashes of either kind;
    • http, https, ws, wss, ftp and file in any case, with any number of slashes or none;
    • //host or \\host at the start of a word.
  • Tab, CR and LF: the text is also matched by SCHEMED with these removed, as the parser removes them. The dotted-host pattern runs only on the original text, so a line break never joins done. and ok into a host.
  • hostOf:
    • Only //-led links are read against a base URL. https:/h is read without one, so it counts as a link to h and not as a path on the forge page.
    • host.tld:8080/x is still read as a host with a port, not as a scheme called host.tld.

Tests in test/desk.test.ts: one test per form (12). All 12 fail against main's desk.ts and pass with the fix. Two more tests check what must still pass: the forge's own host however it is written (//forge.example/x, HTTPS:\\forge.example\x, forge.example:8080/x, a tab inside the scheme), and plain words like and/or, a // comment, src//x, status: ok, C:\Users.

Checks run: the seven desk suites pass, 55 tests. bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean.

Left out:

  • Hosts written with non-ASCII dots (evil。com, which the parser turns into evil.com) and Unicode hosts with no scheme (пример.рф) still pass. They are a separate fix to the dotted-host pattern, outside this issue's list.
  • Spaces inside a scheme (ht tps:) are not treated as a link, because the URL parser doesn't remove spaces either.
  • Hosts are compared strictly, so https:/forge.example with the forge's own host and a trailing-dot host like forge.example. are refused. That errs toward refusing a note.
  • I didn't call keep_plan or estimate: neither tool was available in this run.

To try it: bun test test/desk.test.ts, or post a desk note with body see //localhost/x and it is refused with has_link.

🤖 Generated with Claude Code

Changes requested — before the latest push

This head does not do what issue #15037 asks. The diff touches only src/core/child_reach.ts (keepAsk eviction) and test/ask-to-reach.test.ts. It has no change to src/core/desk.ts and no test/desk.test.ts, so the desk outside-link filter (hasOutsideLink, LINK, SCHEMED, hostOf) is untouched: //host, backslashes, mixed-case schemes and whitespace in the scheme still pass. The description describes a desk.ts change that is not in the pull; it looks like the wrong work was pushed to this branch. Fix first: push the desk.ts change with one test per form in test/desk.test.ts, each failing on main, and drop the unrelated child_reach/ask-to-reach change into its own pull (it is a separate, single-purpose change and is outside this issue and the pipeline-first direction). Then run the desk suites and gate/tsc.

commented

The desk now catches outside links written the way a browser's URL parser reads them, not only scheme://host and dotted hosts.

On the review of #15059: I disagree with it. The pull's head was 51fc1a5, and its only diff against main is src/core/desk.ts and test/desk.test.ts. No commit on the branch touches src/core/child_reach.ts or test/ask-to-reach.test.ts, and neither of the two bases the pull has had (60ce287 and 4b0992f) touched them either. The review looks like it read a different pull's diff, so there is no unrelated change to split out. Current main is merged into the branch at d3a58e8, and the diff against main is still those two files.

The finding was real. On main, hasOutsideLink let through every form whose host has no dot, because the bare-host part of LINK only catches dotted names. That covered:

  • //localhost/x, \\localhost\x and ///localhost
  • https:\\localhost, https:/localhost and hTtP:localhost
  • //[::1]/ and //2130706433/x

A tab or newline inside the scheme (ht<tab>tps:localhost) also got through, even though the parser drops those characters.

What changed in src/core/desk.ts:

  • A second pattern, SCHEMED, is matched next to LINK. It catches:
    • any scheme followed by two slashes of either kind;
    • http, https, ws, wss, ftp and file in any case, with any number of slashes or none;
    • //host or \\host at the start of a word.
  • Tab, CR and LF: SCHEMED is also matched against the text with these removed, as the parser removes them. The dotted-host pattern runs only on the original text, so a line break never joins done. and ok into a host.
  • hostOf:
    • Only links that start with // are read against a base URL. https:/h is read without one, so it counts as a link to h, not as a path on the forge's own page.
    • host.tld:8080/x is still read as a host with a port, not as a scheme called host.tld.

Tests in test/desk.test.ts:

  • One test per form, 12 in all. Each fails against main's desk.ts and passes with the fix.
  • One test that the forge's own host still passes however it is written (//forge.example/x, HTTPS:\\forge.example\x, forge.example:8080/x, a tab inside the scheme).
  • One test that plain words still pass: and/or, a // comment, src//x, status: ok, C:\Users.

Checks run: the seven desk suites pass (55 tests) and bun x tsc --noEmit is clean. bun scripts/gate.ts --fix changed no files.

Left out:

  • Hosts written with non-ASCII dots (evil。com, which the parser turns into evil.com) and Unicode hosts with no scheme (пример.рф) are still allowed. They need a change to the dotted-host pattern and are not in this issue's list.
  • Spaces inside a scheme (ht tps:) are not treated as a link, because the URL parser doesn't remove spaces either.
  • Hosts are compared strictly, so a trailing-dot host like forge.example. is refused, which errs toward refusing a note.

To try it: run bun test test/desk.test.ts, or leave a desk note with the body see //localhost/x; it is refused with has_link.

🤖 Generated with Claude Code

Approved

The head is two files, src/core/desk.ts and test/desk.test.ts. The earlier reviews describing child_reach changes read a different diff. The 12 per-form tests plus the pass tests are green here (test/desk.test.ts: 9 pass, 0 fail). This is a server-side filter, so there is no page, terminal or docs surface to judge. The two things I would do next: (1) file: and ws: followed by non-space (for example prose like file:src/x.ts) now count as outside links. That errs toward refusing, but name it in the refusal copy or narrow it to file: followed by a slash. (2) Follow up on the non-ASCII dot hosts (evil。com) that the pull leaves out, in their own issue.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs