mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 21:59:58 -05:00
repos: check submodule URLs where git resolves them
A relative submodule URL is resolved by git against the repo's remote, and can climb to another host: with the remote https://git.example.com/owner/repo, `../../../10.0.0.5/x` is https://10.0.0.5/x. Relative URLs were allowed unchecked. git now resolves the URLs first (`submodule init` + `sync` write them to the repo's config), and those resolved URLs, the ones git fetches, are checked. A relative URL is never allowed by the check itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4810b8bc50
commit
2dd8e908c2
3 changed files with 61 additions and 28 deletions
|
|
@ -134,14 +134,13 @@ ABSOLUTE_SUBMODULE_URL_RE = re.compile(
|
|||
r'^https://(?P<host>[A-Za-z0-9.-]+|\[[0-9A-Fa-f:.]+\])'
|
||||
r'(?::(?P<port>[0-9]{1,5}))?'
|
||||
r'(?:/[A-Za-z0-9._~%!$&\'()*+,;=:/-]*)?$')
|
||||
RELATIVE_SUBMODULE_URL_RE = re.compile(r'^\.\.?/[A-Za-z0-9._~%/-]*$')
|
||||
|
||||
|
||||
def _check_submodule_url(url: str, repo_host: str) -> Tuple[Optional[str], Optional[Tuple[str, int, List[str]]]]:
|
||||
"""Returns why the URL must not be fetched (or None), and the (host, port, addresses) to pin it to (or None)."""
|
||||
if RELATIVE_SUBMODULE_URL_RE.match(url):
|
||||
# Relative to the repo's own remote.
|
||||
return None, None
|
||||
"""Returns why the URL must not be fetched (or None), and the (host, port, addresses) to pin it to (or None).
|
||||
|
||||
`url` must be absolute: git resolves relative submodule URLs (which can climb to another host, e.g.
|
||||
`../../../10.0.0.1/x`), and the result is checked."""
|
||||
match = ABSOLUTE_SUBMODULE_URL_RE.match(url)
|
||||
if not match:
|
||||
return 'only plain https:// submodule URLs can be downloaded', None
|
||||
|
|
@ -168,8 +167,8 @@ def submodule_url_error(url: str, repo_host: str) -> Optional[str]:
|
|||
"""Why a submodule URL must not be fetched, or None when it may be.
|
||||
|
||||
A submodule's URL is chosen by whoever controls the repo, so it may not make WROLPi fetch from its own network
|
||||
(e.g. `https://localhost:8443/...` or `https://10.0.0.1/...`). Allowed: URLs relative to the repo's remote,
|
||||
the repo's own host (which the user chose), and hosts with only public addresses."""
|
||||
(e.g. `https://localhost:8443/...` or `https://10.0.0.1/...`). Allowed: the repo's own host (which the user
|
||||
chose), and hosts with only public addresses. A relative URL must first be resolved by git."""
|
||||
return _check_submodule_url(url, repo_host)[0]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue