Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
34df1fd
feat(node): add per-IP write-surface rate brake and apply to write_ro…
beardthelion Jul 13, 2026
74e05be
feat(node): extend the per-IP write brake to the remaining write sinks
beardthelion Jul 13, 2026
6fded6e
test(node): adversarial TrustedProxy verification through the write b…
beardthelion Jul 13, 2026
e6324d2
feat(node): purge-spam admin subcommand for the empty-burst cleanup
beardthelion Jul 13, 2026
285d7c7
fix(review): make purge-spam empty-check reject git-discovery reads
beardthelion Jul 13, 2026
090019d
fix(review): normalization-consistent purge, brake helper, CLI + cove…
beardthelion Jul 13, 2026
dfd4f6c
test(review): close the reasoned-not-run gaps by execution
beardthelion Jul 13, 2026
0135419
fix(node): reject path-traversal repo names in purge-spam before remo…
beardthelion Jul 15, 2026
a0fcbb0
fix(node): delete child rows transactionally in delete_repo_by_id
beardthelion Jul 15, 2026
fde9cfe
fix(node): reap write_rate_limiter in the periodic cleanup loop
beardthelion Jul 15, 2026
15522d5
fix(node): hold the per-repo advisory lock across purge recheck+delete
beardthelion Jul 15, 2026
1fcca0d
fix(node): count purge-spam disk-removal failures separately from del…
beardthelion Jul 15, 2026
d9eebd2
fix(node): warn on unparseable rate-limit env vars instead of silentl…
beardthelion Jul 15, 2026
6325402
docs(node): document GITLAWB_IPFS_API/TIGRIS_BUCKET/METRICS_ADDR/SHUT…
beardthelion Jul 15, 2026
bfbe502
test(node): exercise the dry-run guard with a real on-disk candidate …
beardthelion Jul 15, 2026
cdb102e
style(node): cargo fmt for the #196 fix set
beardthelion Jul 15, 2026
4df79f2
fix(node): pin the writer's advisory-lock connection in RepoWriteGuard
beardthelion Jul 15, 2026
68c1f5c
refactor(node): introduce ObjectStore trait seam over TigrisClient
beardthelion Jul 15, 2026
3c1ceb8
fix(node): make purge-spam Tigris-authoritative and archive-deleting
beardthelion Jul 15, 2026
cf669bb
fix(review): don't hold/leak the pool connection in acquire_write
beardthelion Jul 15, 2026
dde5ea9
fix(node): make advisory-lock guards drop-safe and reorder acquire_write
beardthelion Jul 16, 2026
b94d440
fix(node): complete a fully-received push after client disconnect
beardthelion Jul 16, 2026
e4c4161
fix(node): serialize archive uploads under the per-repo advisory lock
beardthelion Jul 16, 2026
6ba698c
fix(node): let purge-spam reach repos that exist only as archives
beardthelion Jul 16, 2026
9f7757c
refactor(node): dedup limiter setup + write-brake test driver; fix .e…
beardthelion Jul 16, 2026
2a78524
docs(node): drop the .env.example shutdown-grace entry #196 added (#196)
beardthelion Jul 19, 2026
c4b337b
fix(node): give advisory-lock guards a dedicated pool and bound the r…
beardthelion Jul 19, 2026
4934646
fix(node): advertise a window-derived Retry-After on rate-limit 429s …
beardthelion Jul 19, 2026
0c279c9
fix(node): skip slug-scoped purge cascade when a mirror row shares th…
beardthelion Jul 19, 2026
86a8228
fix(node): fail closed classifying the purge target directory (#196)
beardthelion Jul 20, 2026
bf2a54e
fix(node): run the push completion tail in the disconnect-surviving t…
beardthelion Jul 20, 2026
c24b541
fix(node): tombstone bounties when their repo is purged (#196)
beardthelion Jul 20, 2026
3baa9ed
fix(node): serialize create_repo against the purge advisory lock (#196)
beardthelion Jul 20, 2026
9916bca
test(node): prove purge deletes at MAX_CONNECTIONS=1 with the split p…
beardthelion Jul 20, 2026
8f3d643
fix(node): fail the push when the durable upload times out, don't 200…
beardthelion Jul 20, 2026
d1e596e
fix(node): tombstone bounties under both owner forms on purge (#196)
beardthelion Jul 20, 2026
ce5dcc3
fix(node): fail closed on a symlink at the purge target (#196)
beardthelion Jul 20, 2026
7dc7be2
fix(node): retry-after on the push-advert 429, and create_repo locks …
beardthelion Jul 20, 2026
d2ba14e
fix(node): correct the create-pool and bounty-tombstone remediations …
beardthelion Jul 20, 2026
5a46ef6
fix(node): close the durable-upload data-loss class on every write pa…
beardthelion Jul 20, 2026
2fa9fa3
chore: merge main (iCaptcha PoW + gl retry tests) into feat/write-sin…
beardthelion Jul 21, 2026
16517f8
refactor(node): route the per-DID 429 through the shared too_many_req…
beardthelion Jul 21, 2026
ba572b3
fix(node): init's background upload waits out the creator's advisory …
beardthelion Jul 21, 2026
859240b
fix(node): roll back the local issue ref before unlock when the durab…
beardthelion Jul 21, 2026
c07435d
fix(node): fork publishes only after a durable upload, serialized on …
beardthelion Jul 21, 2026
2ad1c79
fix(node): read-path downloads publish under the purge lock, without …
beardthelion Jul 21, 2026
b2ca5a7
fix(node): bound every under-lock object-store call and dedup the upl…
beardthelion Jul 21, 2026
fa4322c
fix(node): harden the read-path download against cancellation, stale …
beardthelion Jul 21, 2026
c3d6e73
fix(node): keep the fork's unbounded work out of the target-lock span…
beardthelion Jul 21, 2026
03ef9b5
refactor(node): move read-path download coordination into a repo_stor…
beardthelion Jul 21, 2026
4408d27
fix(node): bound acquire_write's download and free the download-map e…
beardthelion Jul 21, 2026
a12f21a
fix(node): roll back the fork mirror and archive on late clone/insert…
beardthelion Jul 21, 2026
556aa31
fix(node): serialize repo purge cascade with mirror ingest via adviso…
beardthelion Jul 22, 2026
1d8c281
fix(node): roll back local ref on failed durable upload (close/merge/…
beardthelion Jul 22, 2026
1d0d3d2
fix(node): tie cancelled cold-download cleanup to blocking extraction
beardthelion Jul 22, 2026
03cd81e
chore(node): fmt + clippy cleanup for the #196 fixes
beardthelion Jul 22, 2026
9152178
fix(node): never let a failed ref snapshot become a delete-all rollba…
beardthelion Jul 22, 2026
296704f
fix(node): slug-lock every peer-ingest writer and drive the real inge…
beardthelion Jul 22, 2026
1e79ae5
fix(node): own cold-download cleanup in a spawned task so handler can…
beardthelion Jul 22, 2026
ce25bba
refactor(node): delegate issue ref helpers to the store ref primitives
beardthelion Jul 22, 2026
4329b2a
Merge origin/main into feat/write-sink-brake-coverage (reintegrate cu…
beardthelion Jul 22, 2026
d755180
fix(node): slug-lock arweave anchor writes; fail closed when the pre-…
beardthelion Jul 22, 2026
e6f4b2f
fix(node): close review residuals: coalesce cold downloads to one in-…
beardthelion Jul 22, 2026
1459cf2
Merge remote-tracking branch 'origin/main' into feat/write-sink-brake…
beardthelion Nov 11, 2026
da876e8
fix(node): re-apply create/fork purge serialization and restore brake…
beardthelion Nov 11, 2026
edfa6bb
fix(node): close review gaps in purge, locks, and fork cleanup
beardthelion Nov 11, 2026
96ed2b2
fix(node): subscriptions-only ws schema and unsettled-work purge guard
beardthelion Nov 11, 2026
082a37f
Merge remote-tracking branch 'origin/main' into feat/write-sink-brake…
beardthelion Nov 11, 2026
e9e86a1
fix(node): wire close_issue rollback, close purge symlink gap, correc…
beardthelion Nov 11, 2026
1187dca
fix(node): close purge/upload lifecycle gaps from review
beardthelion Nov 11, 2026
261f7ab
fix(node): merge rollback, honest create rollback, purge row recheck
beardthelion Nov 12, 2026
662b9a3
fix(node): probe purge slug liveness, gate issue write brake behind t…
beardthelion Nov 12, 2026
43d4f59
fix(node): close-issue rollback uses resolved ref, drop router brake …
beardthelion Nov 12, 2026
4b483a3
fix(node): close_issue spends neither bucket when either cap refuses,…
beardthelion Nov 12, 2026
11cadb9
fix(node): refund the write slot when the close cap refuses, send Ret…
beardthelion Nov 12, 2026
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(review): normalization-consistent purge, brake helper, CLI + cove…
…rage

Addresses the remaining code-review findings:
- purge-spam DID matching now uses did:key normalization on both sides
  (list_repos_by_owner_did via OWNER_KEY_CASE_SQL, is_excluded and the target
  scope via normalize_owner_key), so short/full form is consistent and an
  excluded identity is protected in either form. Adds a short-form exclusion test.
- Extract the per-IP write brake into a chainable WriteBraked helper so a future
  write group can't silently ship unbraked (kept separate from add_auth_layers
  by design; documented why).
- Mark --repos-dir / --database-url global so admin subcommands accept them after
  the subcommand (was an 'unexpected argument' parse error); verified.
- Document GITLAWB_WRITE_RATE_LIMIT in .env.example incl. the per-IP NAT-aggregate
  caveat so operators can size it.
- Coverage: adoption-floor (under-limit write passes), write-limit=0 disables,
  task/bounty/profile route-level 429s, /graphql/ws stays unbraked.

Full suite 927 pass / 0 fail; fmt + clippy -D warnings clean.
  • Loading branch information
beardthelion committed Jul 13, 2026
commit 090019deb7dbb921998e267aab81820e00beed2b
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ GITLAWB_PUSH_RATE_LIMIT=600
# the client IP. 0 disables. Default 120.
GITLAWB_CREATE_RATE_LIMIT=120

# ── Write rate limiting (non-creation authenticated writes) ───────────────
# Max non-creation write requests per client IP per hour: issue/PR comments,
# labels, stars, merges, protect/unprotect, replicas, visibility, tasks,
# bounties, profile, and GraphQL mutations. Its own bucket, separate from the
# creation and push brakes. Uses GITLAWB_TRUSTED_PROXY to resolve the client IP.
# NOTE: this is a per-IP aggregate across ALL those write actions, so behind a
# shared NAT/egress IP (or with GITLAWB_TRUSTED_PROXY unset) many users collapse
# onto one bucket — raise this for automation-heavy or multi-user single-IP
# deployments. 0 disables. Default 600.
GITLAWB_WRITE_RATE_LIMIT=600

# ── Peer-sync rate limiting (per client IP, uses GITLAWB_TRUSTED_PROXY below) ─
# /api/v1/peers/announce and /api/v1/sync/notify accept unsigned requests from
# known peers and run at higher frequency, so a generous bucket. Separate from
Expand Down
43 changes: 39 additions & 4 deletions crates/gitlawb-node/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ pub struct Candidate {
pub ref_count: usize,
}

/// Whether a DID is on the hard exclusion list.
/// Whether a DID is on the hard exclusion list. Compared under did:key
/// normalization (the same convention the repos table and every ownership check
/// use), so an excluded identity stored in either `did:key:z6…` or bare `z6…`
/// form is protected regardless of the form the exclusion constant is written in.
fn is_excluded(owner_did: &str) -> bool {
EXCLUDED_DIDS.contains(&owner_did)
let owner_key = crate::db::normalize_owner_key(owner_did);
EXCLUDED_DIDS
.iter()
.any(|d| crate::db::normalize_owner_key(d) == owner_key)
}

/// Pure candidate selector — the security core, isolated from disk and DB so the
Expand Down Expand Up @@ -73,8 +79,11 @@ where
if is_excluded(&repo.owner_did) {
continue;
}
// Scope to the named burst only.
if repo.owner_did != target_did {
// Scope to the named burst only, under did:key normalization so a burst
// row stored in either did:key or bare form is matched consistently.
if crate::db::normalize_owner_key(&repo.owner_did)
!= crate::db::normalize_owner_key(target_did)
{
continue;
}
// Per-repo empty check.
Expand Down Expand Up @@ -526,4 +535,30 @@ mod db_tests {
"the purge target must never be an excluded (protected) DID"
);
}

/// Exclusion is normalization-consistent: an excluded identity stored in the
/// bare short form (as mirror upserts write it) is still excluded, even though
/// the exclusion constants are full did:key form — and an empty repo it owns
/// is never selected.
#[test]
fn short_form_excluded_did_is_still_protected() {
let short = crate::db::normalize_owner_key(EXCLUDED_DIDS[1]); // bare z6MkqRz…
assert_ne!(
short, EXCLUDED_DIDS[1],
"fixture must actually be short form"
);
assert!(
is_excluded(short),
"short-form of an excluded DID must be excluded"
);

// An empty repo owned by the short-form excluded DID is spared even though
// its ref signature (0) otherwise matches the burst.
let empty_excluded_short = rec("x-short", short, "spam");
let cands = select_spam_candidates(&[empty_excluded_short], SPAM_BURST_TARGET_DID, |_| 0);
assert!(
cands.is_empty(),
"an empty repo owned by a short-form excluded DID must never be a candidate"
);
}
}
136 changes: 136 additions & 0 deletions crates/gitlawb-node/src/api/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2786,4 +2786,140 @@ mod tests {
"issue-write routes must be IP-throttled by the write brake"
);
}

// Adoption floor: an under-limit write must NOT be throttled. Guards against
// an off-by-one that braked the first request (invisible to the 429 tests,
// which all pre-exhaust the bucket).
#[sqlx::test]
async fn under_limit_write_is_not_throttled(pool: sqlx::PgPool) {
use axum::body::Body;
use axum::extract::ConnectInfo;
use axum::http::{Method, Request, StatusCode};
use std::net::SocketAddr;
use std::time::Duration;
use tower::ServiceExt;

let mut state = crate::test_support::test_state(pool).await;
// Ample budget; bucket NOT exhausted.
state.write_rate_limiter =
crate::rate_limit::RateLimiter::new(100, Duration::from_secs(60));
state.push_limiter_trust = crate::rate_limit::TrustedProxy::None;
let peer: SocketAddr = "203.0.113.150:7000".parse().unwrap();

let router = crate::server::build_router(state);
let mut req = Request::builder()
.method(Method::PUT)
.uri("/api/v1/repos/someowner/somerepo/star")
.body(Body::empty())
.unwrap();
req.extensions_mut().insert(ConnectInfo(peer));
assert_ne!(
router.oneshot(req).await.unwrap().status(),
StatusCode::TOO_MANY_REQUESTS,
"an under-limit write must pass the brake, not be 429'd"
);
}

// GITLAWB_WRITE_RATE_LIMIT=0 disables the brake end-to-end: no write is 429'd
// however many arrive from one IP.
#[sqlx::test]
async fn write_rate_limit_zero_disables_the_brake(pool: sqlx::PgPool) {
use axum::body::Body;
use axum::extract::ConnectInfo;
use axum::http::{Method, Request, StatusCode};
use std::net::SocketAddr;
use std::time::Duration;
use tower::ServiceExt;

let mut state = crate::test_support::test_state(pool).await;
state.write_rate_limiter = crate::rate_limit::RateLimiter::new(0, Duration::from_secs(60));
state.push_limiter_trust = crate::rate_limit::TrustedProxy::None;
let peer: SocketAddr = "203.0.113.151:7000".parse().unwrap();

let router = crate::server::build_router(state);
for _ in 0..5 {
let mut req = Request::builder()
.method(Method::PUT)
.uri("/api/v1/repos/someowner/somerepo/star")
.body(Body::empty())
.unwrap();
req.extensions_mut().insert(ConnectInfo(peer));
assert_ne!(
router.clone().oneshot(req).await.unwrap().status(),
StatusCode::TOO_MANY_REQUESTS,
"a 0 write limit must disable the brake"
);
}
}

// The task/bounty/profile write groups share the write brake (same
// attachment as write_routes); prove each 429s at the route level.
#[sqlx::test]
async fn task_bounty_profile_writes_are_rate_limited(pool: sqlx::PgPool) {
use axum::body::Body;
use axum::extract::ConnectInfo;
use axum::http::{Method, Request, StatusCode};
use std::net::SocketAddr;
use std::time::Duration;
use tower::ServiceExt;

let mut state = crate::test_support::test_state(pool).await;
state.write_rate_limiter = crate::rate_limit::RateLimiter::new(1, Duration::from_secs(60));
state.push_limiter_trust = crate::rate_limit::TrustedProxy::None;
let peer: SocketAddr = "203.0.113.152:7000".parse().unwrap();
assert!(state.write_rate_limiter.check(&peer.ip().to_string()).await);

let router = crate::server::build_router(state);
for (method, uri) in [
(Method::POST, "/api/v1/tasks"),
(Method::POST, "/api/v1/repos/o/r/bounties"),
(Method::PUT, "/api/v1/profile"),
] {
let mut req = Request::builder()
.method(method)
.uri(uri)
.header("content-type", "application/json")
.body(Body::from("{}"))
.unwrap();
req.extensions_mut().insert(ConnectInfo(peer));
assert_eq!(
router.clone().oneshot(req).await.unwrap().status(),
StatusCode::TOO_MANY_REQUESTS,
"write group {uri} must be IP-throttled by the write brake"
);
}
}

// /graphql/ws (subscriptions) is deliberately mounted AFTER the write brake
// layer, so it must stay unbraked even when the write bucket is exhausted.
#[sqlx::test]
async fn graphql_ws_is_not_braked(pool: sqlx::PgPool) {
use axum::body::Body;
use axum::extract::ConnectInfo;
use axum::http::{Method, Request, StatusCode};
use std::net::SocketAddr;
use std::time::Duration;
use tower::ServiceExt;

let mut state = crate::test_support::test_state(pool).await;
state.write_rate_limiter = crate::rate_limit::RateLimiter::new(1, Duration::from_secs(60));
state.push_limiter_trust = crate::rate_limit::TrustedProxy::None;
let peer: SocketAddr = "203.0.113.153:7000".parse().unwrap();
assert!(state.write_rate_limiter.check(&peer.ip().to_string()).await);

let router = crate::server::build_router(state);
let mut req = Request::builder()
.method(Method::GET)
.uri("/graphql/ws")
.body(Body::empty())
.unwrap();
req.extensions_mut().insert(ConnectInfo(peer));
// Not a real ws upgrade, so the subscription service rejects it with some
// non-429 status; the point is the write brake never sees it.
assert_ne!(
router.oneshot(req).await.unwrap().status(),
StatusCode::TOO_MANY_REQUESTS,
"/graphql/ws must not be behind the write brake"
);
}
}
16 changes: 12 additions & 4 deletions crates/gitlawb-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ pub struct Config {
#[command(subcommand)]
pub command: Option<Command>,

/// Directory where bare git repositories are stored
#[arg(long, env = "GITLAWB_REPOS_DIR", default_value = "./data/repos")]
/// Directory where bare git repositories are stored. `global` so it can
/// follow a subcommand (e.g. `gitlawb-node purge-spam --repos-dir …`).
#[arg(
long,
env = "GITLAWB_REPOS_DIR",
default_value = "./data/repos",
global = true
)]
pub repos_dir: PathBuf,

/// PostgreSQL connection URL (Supabase or any Postgres instance)
/// PostgreSQL connection URL (Supabase or any Postgres instance). `global` so
/// admin subcommands accept it in either position.
#[arg(
long,
env = "DATABASE_URL",
default_value = "postgresql://localhost/gitlawb"
default_value = "postgresql://localhost/gitlawb",
global = true
)]
pub database_url: String,

Expand Down
26 changes: 15 additions & 11 deletions crates/gitlawb-node/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,20 +1260,24 @@ impl Db {
Ok(())
}

/// Every repo row owned by exactly `owner_did` (an exact `owner_did` match, no
/// did:key normalization and no dedup) so a caller enumerating one DID's repos
/// sees every physical row. Backs the `purge-spam` admin tool, whose selection
/// then applies its own per-repo empty check and exclusion gate. Ordered by
/// `id` for a stable candidate listing.
/// Every repo row whose owner resolves to `owner_did` under did:key
/// normalization, so `did:key:z6…` and bare `z6…` rows of the same identity
/// both match (mirroring how ownership is resolved everywhere else via
/// `OWNER_KEY_CASE_SQL` / the `idx_repos_owner_key_name` index). No dedup, so a
/// caller enumerating one DID's repos sees every physical row. Backs the
/// `purge-spam` admin tool, whose selection then applies its own per-repo empty
/// check and exclusion gate (both normalization-consistent). Ordered by `id`.
pub async fn list_repos_by_owner_did(&self, owner_did: &str) -> Result<Vec<RepoRecord>> {
let rows = sqlx::query(
let sql = format!(
"SELECT id, name, owner_did, description, is_public, default_branch,
created_at, updated_at, disk_path, forked_from, machine_id
FROM repos WHERE owner_did = $1 ORDER BY id",
)
.bind(owner_did)
.fetch_all(&self.pool)
.await?;
FROM repos WHERE {key} = $1 ORDER BY id",
key = OWNER_KEY_CASE_SQL
);
let rows = sqlx::query(&sql)
.bind(normalize_owner_key(owner_did))
.fetch_all(&self.pool)
.await?;
Ok(rows.into_iter().map(row_to_repo).collect())
}

Expand Down
36 changes: 24 additions & 12 deletions crates/gitlawb-node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ fn add_auth_layers(router: Router<AppState>, state: AppState) -> Router<AppState
.layer(middleware::from_fn(auth::require_signature))
}

/// Attach the shared per-IP write brake to an authenticated write-route group,
/// outermost so a flood is rejected before signature verification. Every
/// authenticated non-creation write group MUST call this or it silently ships
/// unbraked with no compile error. Deliberately a separate call, NOT folded into
/// `add_auth_layers`: the creation routes use a different bucket
/// (`create_ip_rate_limiter`) and the graphql group is not built through
/// `add_auth_layers`, so a helper keyed on auth would attach the wrong limiter.
trait WriteBraked {
fn write_braked(self, limiter: &rate_limit::IpRateLimiter) -> Self;
}

impl WriteBraked for Router<AppState> {
fn write_braked(self, limiter: &rate_limit::IpRateLimiter) -> Self {
self.layer(middleware::from_fn(rate_limit::rate_limit_by_ip))
.layer(axum::Extension(limiter.clone()))
Comment thread
beardthelion marked this conversation as resolved.
Resolved
}
}

pub fn build_router(state: AppState) -> Router {
// ── GraphQL routes ─────────────────────────────────────────────────────
let schema = state.graphql_schema.as_ref().clone();
Expand All @@ -77,8 +95,7 @@ pub fn build_router(state: AppState) -> Router {
// a mutation POST, so it counts every /graphql request — acceptable, both
// cost work); /graphql/ws subscriptions stay unbraked.
.layer(middleware::from_fn(auth::optional_signature))
.layer(middleware::from_fn(rate_limit::rate_limit_by_ip))
.layer(axum::Extension(write_ip_limiter.clone()))
.write_braked(&write_ip_limiter)
.route_service("/graphql/ws", GraphQLSubscription::new(schema));

// ── Task routes (write — require HTTP Signature + per-IP write brake) ──
Expand All @@ -90,8 +107,7 @@ pub fn build_router(state: AppState) -> Router {
.route("/api/v1/tasks/{id}/fail", post(tasks::fail_task)),
state.clone(),
)
.layer(middleware::from_fn(rate_limit::rate_limit_by_ip))
.layer(axum::Extension(write_ip_limiter.clone()));
.write_braked(&write_ip_limiter);

// ── Task routes (read — open) ──────────────────────────────────────────
let task_read_routes = Router::new()
Expand Down Expand Up @@ -205,8 +221,7 @@ pub fn build_router(state: AppState) -> Router {
),
state.clone(),
)
.layer(middleware::from_fn(rate_limit::rate_limit_by_ip))
.layer(axum::Extension(write_ip_limiter.clone()));
.write_braked(&write_ip_limiter);

// Body limit is raised to GITLAWB_MAX_PACK_BYTES (default 2 GB) for git
// routes only — all other API routes keep axum's default 2 MB cap.
Expand Down Expand Up @@ -273,8 +288,7 @@ pub fn build_router(state: AppState) -> Router {
),
state.clone(),
)
.layer(middleware::from_fn(rate_limit::rate_limit_by_ip))
.layer(axum::Extension(write_ip_limiter.clone()));
.write_braked(&write_ip_limiter);

// ── Bounty routes (read — open) ──────────────────────────────────────
let bounty_read_routes = Router::new()
Expand All @@ -296,8 +310,7 @@ pub fn build_router(state: AppState) -> Router {
Router::new().route("/api/v1/profile", axum::routing::put(profiles::set_profile)),
state.clone(),
)
.layer(middleware::from_fn(rate_limit::rate_limit_by_ip))
.layer(axum::Extension(write_ip_limiter.clone()));
.write_braked(&write_ip_limiter);

// ── Issue routes (write — require HTTP Signature + per-IP write brake) ─
let issue_write_routes = add_auth_layers(
Expand All @@ -312,8 +325,7 @@ pub fn build_router(state: AppState) -> Router {
),
state.clone(),
)
.layer(middleware::from_fn(rate_limit::rate_limit_by_ip))
.layer(axum::Extension(write_ip_limiter.clone()));
.write_braked(&write_ip_limiter);

// ── Peer discovery routes ─────────────────────────────────────────────
// Peer writes accept signatures when present and can require them after a
Expand Down