Skip to content

fix(core): reject relative path segments in repository hosts - #51577

Merged
nexxeln merged 1 commit into
anomalyco:v2from
nkootstra:reference-host-validation
Sep 28, 2026
Merged

nexxeln merged 1 commit into
anomalyco:v2from
nkootstra:reference-host-validation

Conversation

@nkootstra

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #51576

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Repository.cachePath turns each :-separated host part into a directory. safeHost didn't reject . or .., so a reference like ..:docs got a cache path outside the repos cache root. RepositoryCache.ensure then deleted that path, because it wasn't a matching checkout.

This change checks every host part with the existing safeSegment rule, the same rule already used for path segments. These references now fail in parseRemote, and Reference never hands them to the cache. Valid hosts, including ones with a port, parse the same as before.

How did you verify your code works?

  • I added tests in repository.test.ts. The new host cases fail without the fix and pass with it. Another test checks that a host with a port keeps its cache path.
  • I reproduced the deletion in a temp dir with the real RepositoryCache before the fix, and it no longer happens after.
  • bun test and bun typecheck in packages/core. The suite shows the same pre-existing failures before and after; those tests need network access.

Screenshots / recordings

N/A, not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Repository.cachePath turns each `:`-separated part of a reference host
into a directory under the repos cache root. The host check only
rejected whitespace, slashes and a leading dash, so hosts such as `..`
(from `..:name`, `ssh://../repo` or `https://%2e%2e/...`) produced a
cache path one level above the root. RepositoryCache.ensure then
recursively removed that path when it was not a matching checkout, so a
`references` entry in project config could delete data next to the
cache on refresh.

Validate every host part with the same rule already used for path
segments, so such references are rejected at parse time and never reach
the cache.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@nexxeln
nexxeln merged commit 39e1ce5 into anomalyco:v2 Sep 28, 2026
10 checks passed
@nkootstra
nkootstra deleted the reference-host-validation branch September 28, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants