Skip to content

Do not resolve home-relative chat links against the project root - #1796

Merged
SawyerHood merged 1 commit into
mainfrom
bb/draft-pr-for-1182-chat-links-starting-with-resol-thr_5nye36hxu8
Aug 18, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/draft-pr-for-1182-chat-links-starting-with-resol-thr_5nye36hxu8

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

What was wrong

When an assistant message contains a shell-style home path such as ~/.config/example.md (inline code that ends in .md, or an explicit [text](~/…) link), the app renders it as a local-file link. resolveRelativeLocalFileHref in apps/app/src/components/ui/markdown-local-file-link.ts rejects absolute paths, fragments, queries, and URI schemes, and then treats every other href as workspace-relative. The path became <workspace>/~/.config/example.md, which passed the containment checks. A click opened a workspace file tab that said Failed to load file, and Open in editor failed with Open target path does not exist: <workspace>/~/.config/example.md.

What changed

  • apps/app/src/components/ui/markdown-local-file-link.ts: add isHomeRelativePath with the pattern /^~(?:[^/]*\/|$)/u and include it in the early-return guard of resolveRelativeLocalFileHref, next to the startsWith("/") check. The check runs on the decoded href, so %7E/… is covered. It matches ~, ~/…, and ~user/…. Names that only start with ~ (~notes.md, ~$report.docx, docs/~draft.md) stay relative files.
  • apps/app/src/components/ui/markdown-local-file-link.test.ts: add 6 home-relative cases that must resolve to null and 4 positive cases that must still resolve as relative files.

The fix follows the report's proposal with no deviation. Home-directory expansion (option 2 in the report) needs a host payload field and a protocol version bump. That is a separate change.

How I verified

  • pnpm exec vitest run src/components/ui/markdown-local-file-link.test.ts on the base commit with only the test change: 6 failed / 15 passed. With the fix: 21 passed.
  • pnpm exec turbo run typecheck --filter=@bb/app: clean.
  • pnpm exec turbo run test --filter=@bb/app: 360 files, 2852 tests passed.

Fixes #1182

Report: https://get-bb.github.io/reports/issues/1182.html

AGENT GENERATED: by Claude Opus 5

resolveRelativeLocalFileHref treated every non-absolute href as
workspace-relative, so `~/.config/example.md` became
`<root>/~/.config/example.md` and opened a broken workspace file tab.
Add a home-relative guard (`~`, `~/…`, `~user/…`) next to the absolute
path check. Names that merely start with `~` stay relative.

Fixes #1182

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood marked this pull request as ready for review August 18, 2026 18:21

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

I am reviewing this pull request now. I will check security, code quality, architecture, performance, tests, and the user flow.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain English summary: This change stops BB from treating home paths such as ~/.config/file as files inside the current project. Ordinary filenames such as ~notes.md still work as project files.

I found no defect caused by this pull request.

  • Security: The new check runs after one URI decode and before path joining. Existing path normalization still blocks ordinary traversal attempts.
  • Code quality: The focused cases cover bare, encoded, suffixed, and named-user home paths. They also protect valid tilde-prefixed project names.
  • Architecture: The codebase has no matching home-path helper that should replace this local check. Other tilde checks expand different configuration or host paths.
  • Performance: The new pattern adds one linear scan per relative link. It adds no I/O or state work.

I found one older, non-blocking issue. The Markdown flow can decode some values twice through its parse-resolve-parse sequence. A separate change should define one decode step and add combined-flow tests for %257E and double-encoded dot segments.

Validation passed across 44 focused tests, git diff --check, and all current GitHub checks. The worktree stayed clean.

I started the isolated development app, and it returned HTTP 200. Dev-browser read the page title, but the page body stayed empty and timed out. I could not complete the live click test, and I stopped the isolated instance.

This is a comment-only review. I did not approve or request changes.

@SawyerHood
SawyerHood merged commit 88564b6 into main Aug 18, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/draft-pr-for-1182-chat-links-starting-with-resol-thr_5nye36hxu8 branch August 18, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat links starting with ~/ resolve against the project root

1 participant