Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(node): close mirror review blockers
Origin-Session: local-d6a143 | Codex | 20 prompts
  • Loading branch information
gnanam1990 committed Aug 14, 2026
commit 5b9e06d501e86b2145ec8230c4936fde43dc7995
6 changes: 4 additions & 2 deletions crates/gitlawb-node/src/api/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ fn embedded_ipv4(v6: std::net::Ipv6Addr) -> Option<std::net::Ipv4Addr> {

/// Whether a peer `http_url` is a public http(s) endpoint safe to register.
/// Rejects non-http(s) schemes, loopback/unspecified/private/link-local IPs,
/// and `localhost` / `.local` / `.internal` hostnames. Used at announce time
/// and by the boot-time prune of already-poisoned rows.
/// and `localhost` / `.localhost` / `.local` / `.internal` hostnames. Used at
/// announce time and by the boot-time prune of already-poisoned rows.
pub fn is_public_http_url(raw: &str) -> bool {
let url = match reqwest::Url::parse(raw) {
Ok(u) => u,
Expand All @@ -125,6 +125,7 @@ pub fn is_public_http_url(raw: &str) -> bool {
}
if host.is_empty()
|| host == "localhost"
|| host.ends_with(".localhost")
|| host.ends_with(".local")
|| host.ends_with(".internal")
{
Expand Down Expand Up @@ -529,6 +530,7 @@ mod tests {
fn rejects_loopback_private_and_internal() {
for bad in [
"http://localhost:7545",
"http://node.localhost:7545",
"http://127.0.0.1:5432/",
"http://localhost:22/",
"http://0.0.0.0:7545",
Expand Down
40 changes: 36 additions & 4 deletions crates/gitlawb-node/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ fn validate_mirror_upstream_url(raw: &str) -> Result<reqwest::Url> {
if url.scheme() != "https" {
anyhow::bail!("mirror upstream URL must use HTTPS");
}
if !crate::api::peers::is_public_http_url(raw) {
anyhow::bail!("mirror upstream URL must use a public host");
}
if url.host_str().is_none() || url.path().trim_matches('/').is_empty() {
anyhow::bail!("mirror upstream URL must include a host and repository path");
}
Expand Down Expand Up @@ -3416,6 +3419,17 @@ mod mirror_state_tests {
"https://github.com/Gitlawb/node.git#main",
"https://github.com/",
"https://github.com/Gitlawb/node.git\n",
"https://localhost/Gitlawb/node.git",
"https://forge.localhost/Gitlawb/node.git",
"https://127.0.0.1/Gitlawb/node.git",
"https://[::1]/Gitlawb/node.git",
"https://169.254.169.254/Gitlawb/node.git",
"https://10.0.0.5/Gitlawb/node.git",
"https://172.16.0.5/Gitlawb/node.git",
"https://192.168.1.5/Gitlawb/node.git",
"https://forge.internal/Gitlawb/node.git",
"https://[::ffff:127.0.0.1]/Gitlawb/node.git",
"https://[64:ff9b::7f00:1]/Gitlawb/node.git",
] {
assert!(
validate_mirror_upstream_url(invalid).is_err(),
Expand Down Expand Up @@ -3792,16 +3806,34 @@ mod mirror_state_tests {
}

#[sqlx::test]
async fn peer_mirror_rows_cannot_become_continuous_upstreams(pool: PgPool) {
async fn continuous_mirror_uuid_gate_leaves_peer_rows_untouched(pool: PgPool) {
let db = migrated_db(pool).await;
db.upsert_mirror_repo("z6MkPeer", "repo", "/srv/peer/repo.git", None, false)
.await
.unwrap();

let result = db
let error = db
.configure_inbound_mirror("z6MkPeer/repo", "https://github.com/Gitlawb/node.git")
.await;
assert!(result.is_err());
.await
.unwrap_err();
assert!(
format!("{error:#}")
.contains("continuous mirrors require a canonical UUID repository id"),
"unexpected error: {error:#}"
);

let unchanged: (Option<String>, Option<String>) =
sqlx::query_as("SELECT upstream_url, mirror_status FROM repos WHERE id = $1")
.bind("z6MkPeer/repo")
.fetch_one(db.pool())
.await
.unwrap();
assert_eq!(unchanged, (None, None));
assert!(db
.get_repo_mirror_state("z6MkPeer/repo")
.await
.unwrap()
.is_none());
}
}

Expand Down