Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4506480
fix(node): gate GET /ipfs/{cid} on reachable allowed-set, not deny-se…
Gravirei Jun 30, 2026
3aa7bf0
perf(ipfs): check object existence before allowed-blob walk
Gravirei Jun 30, 2026
63580c7
refactor(ipfs): improve formatting and readability in get_by_cid func…
Gravirei Jun 30, 2026
002f354
refactor(ipfs): streamline object retrieval by separating type and co…
Gravirei Jun 30, 2026
f2c91a8
docs(ipfs): update get_by_cid comment to reflect split object retrieval
Gravirei Jul 1, 2026
0b7c494
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 1, 2026
03ba714
Run cargo fmt on store.rs
Gravirei Jul 1, 2026
03c90f8
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 2, 2026
94bb216
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 3, 2026
79650df
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 5, 2026
26d8d48
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 6, 2026
3ec0acc
fix(visibility): gate repo-scoped read surfaces on visibility (#120)
Gravirei Jul 6, 2026
f3b08c1
fix(visibility): enhance repo read authorization checks and improve t…
Gravirei Jul 6, 2026
459e21e
Fix review feedback: clamp limit, memoize authz, identical 404 body, …
Gravirei Jul 7, 2026
6fd29c9
cargo update -p crossbeam-epoch: fix RUSTSEC-2026-0204 (invalid point…
Gravirei Jul 7, 2026
119bfb1
Fix review findings: correct authz memoization, page past hidden boun…
Gravirei Jul 7, 2026
0be5e42
Fix findings: sign CLI/MCP reads, keyset pagination, gate claim_bounty
Gravirei Jul 7, 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
Fix findings: sign CLI/MCP reads, keyset pagination, gate claim_bounty
  • Loading branch information
Gravirei committed Jul 7, 2026
commit 0be5e42d505b976fe9ee320fa20ad20ab1e64f95
57 changes: 46 additions & 11 deletions crates/gitlawb-node/src/api/bounties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ pub async fn list_repo_bounties(
let limit = q.limit.unwrap_or(50).clamp(1, MAX_BOUNTY_LIMIT);
let bounties = state
.db
.list_bounties(Some(&owner), Some(&repo), q.status.as_deref(), limit, 0)
.list_bounties(
Some(&owner),
Some(&repo),
q.status.as_deref(),
limit,
None,
None,
)
.await?;

Ok(Json(serde_json::json!({ "bounties": bounties })))
Expand All @@ -144,18 +151,35 @@ pub async fn list_all_bounties(
let mut memo = std::collections::HashMap::new();
let mut allowed: Vec<BountyRecord> = Vec::new();
let page_size = (limit * 5).clamp(1, 200);
let max_rows = 10_000i64;
let mut scanned: i64 = 0;
let max_scanned = 10_000i64;
let mut total_scanned: i64 = 0;
let mut cursor: Option<(String, String)> = None;

while (allowed.len() as i64) < limit && scanned < max_rows {
while (allowed.len() as i64) < limit {
let after = cursor.as_ref().map(|(ts, id)| (ts.as_str(), id.as_str()));
let bounties = state
.db
.list_bounties(None, None, q.status.as_deref(), page_size, scanned)
.list_bounties(
None,
None,
q.status.as_deref(),
page_size,
after.map(|(ts, _)| ts),
after.map(|(_, id)| id),
)
.await?;
if bounties.is_empty() {
break;
}

total_scanned += bounties.len() as i64;
if total_scanned > max_scanned {
return Err(AppError::Incomplete(
"too many rows scanned; refine your filters".into(),
));
}

let last = bounties.last().unwrap();
for b in &bounties {
if (allowed.len() as i64) >= limit {
break;
Expand All @@ -180,7 +204,7 @@ pub async fn list_all_bounties(
allowed.push(b.clone());
}
}
scanned += bounties.len() as i64;
cursor = Some((last.created_at.clone(), last.id.clone()));
}

Ok(Json(serde_json::json!({ "bounties": allowed })))
Expand Down Expand Up @@ -214,11 +238,22 @@ pub async fn claim_bounty(
Path(id): Path<String>,
Json(req): Json<ClaimBountyRequest>,
) -> Result<Json<BountyRecord>> {
let bounty = state
.db
.get_bounty(&id)
.await?
.ok_or_else(|| AppError::NotFound(format!("bounty {id} not found")))?;
let not_found = || AppError::NotFound(format!("bounty {id} not found"));

let bounty = state.db.get_bounty(&id).await?.ok_or_else(not_found)?;

if crate::api::authorize_repo_read(
&state,
&bounty.repo_owner,
&bounty.repo_name,
Some(auth.0.as_str()),
"/",
)
.await
.is_err()
{
return Err(not_found());
}

if bounty.status != "open" {
return Err(AppError::BadRequest(format!(
Expand Down
17 changes: 11 additions & 6 deletions crates/gitlawb-node/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2935,7 +2935,8 @@ impl Db {
repo_name: Option<&str>,
status: Option<&str>,
limit: i64,
offset: i64,
after_created_at: Option<&str>,
after_id: Option<&str>,
) -> Result<Vec<BountyRecord>> {
let mut sql = String::from("SELECT * FROM bounties WHERE 1=1");
let mut binds: Vec<String> = Vec::new();
Expand All @@ -2956,17 +2957,21 @@ impl Db {
binds.push(s.to_string());
idx += 1;
}
sql.push_str(&format!(
" ORDER BY created_at DESC LIMIT ${idx} OFFSET ${}",
idx + 1
));
if let Some(ts) = after_created_at {
let id = after_id.unwrap_or("");
sql.push_str(&format!(" AND (created_at, id) < (${idx}, ${})", idx + 1));
binds.push(ts.to_string());
idx += 1;
binds.push(id.to_string());
idx += 1;
}
sql.push_str(&format!(" ORDER BY created_at DESC, id DESC LIMIT ${idx}"));

let mut q = sqlx::query(&sql);
for b in &binds {
q = q.bind(b);
}
q = q.bind(limit);
q = q.bind(offset);

let rows = q.fetch_all(&self.pool).await?;
Ok(rows.iter().map(|r| self.bounty_from_row(r)).collect())
Expand Down
6 changes: 6 additions & 0 deletions crates/gitlawb-node/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub enum AppError {
#[error("too many requests: {0}")]
TooManyRequests(String),

#[error("incomplete: {0}")]
Incomplete(String),

#[error("git error: {0}")]
Git(String),

Expand Down Expand Up @@ -98,6 +101,9 @@ impl IntoResponse for AppError {
AppError::TooManyRequests(msg) => {
(StatusCode::TOO_MANY_REQUESTS, "rate_limited", msg.clone())
}
AppError::Incomplete(msg) => {
(StatusCode::UNPROCESSABLE_ENTITY, "incomplete", msg.clone())
}
AppError::Git(msg) => (StatusCode::INTERNAL_SERVER_ERROR, "git_error", msg.clone()),
AppError::Db(e) => (StatusCode::INTERNAL_SERVER_ERROR, "db_error", e.to_string()),
AppError::Internal(e) => (
Expand Down
38 changes: 28 additions & 10 deletions crates/gl/src/bounty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use std::path::PathBuf;
use crate::http::NodeClient;
use crate::identity::load_keypair_from_dir;

fn signed_client(node: &str, dir: Option<&std::path::Path>) -> NodeClient {
NodeClient::new(node, load_keypair_from_dir(dir).ok())
}

#[derive(Args)]
pub struct BountyArgs {
#[command(subcommand)]
Expand Down Expand Up @@ -49,13 +53,17 @@ pub enum BountyCmd {
status: Option<String>,
#[arg(long, default_value = "https://node.gitlawb.com", env = "GITLAWB_NODE")]
node: String,
#[arg(long)]
dir: Option<PathBuf>,
},
/// Show details of a specific bounty
Show {
/// Bounty ID
id: String,
#[arg(long, default_value = "https://node.gitlawb.com", env = "GITLAWB_NODE")]
node: String,
#[arg(long)]
dir: Option<PathBuf>,
},
/// Claim an open bounty
Claim {
Expand Down Expand Up @@ -121,8 +129,13 @@ pub async fn run(args: BountyArgs) -> Result<()> {
node,
dir,
} => cmd_create(repo, title, amount, issue, tx_hash, deadline, node, dir).await,
BountyCmd::List { repo, status, node } => cmd_list(repo, status, node).await,
BountyCmd::Show { id, node } => cmd_show(id, node).await,
BountyCmd::List {
repo,
status,
node,
dir,
} => cmd_list(repo, status, node, dir).await,
BountyCmd::Show { id, node, dir } => cmd_show(id, node, dir).await,
BountyCmd::Claim {
id,
wallet,
Expand Down Expand Up @@ -192,8 +205,13 @@ async fn cmd_create(
Ok(())
}

async fn cmd_list(repo: Option<String>, status: Option<String>, node: String) -> Result<()> {
let client = NodeClient::new(&node, None);
async fn cmd_list(
repo: Option<String>,
status: Option<String>,
node: String,
dir: Option<PathBuf>,
) -> Result<()> {
let client = signed_client(&node, dir.as_deref());

let url = if let Some(ref repo) = repo {
let (owner, name) = repo
Expand All @@ -214,7 +232,7 @@ async fn cmd_list(repo: Option<String>, status: Option<String>, node: String) ->
};

let resp = client
.get(&url)
.get_authed(&url)
.await
.context("failed to connect to node")?;
let body: Value = resp.json().await.unwrap_or_default();
Expand All @@ -237,9 +255,9 @@ async fn cmd_list(repo: Option<String>, status: Option<String>, node: String) ->
Ok(())
}

async fn cmd_show(id: String, node: String) -> Result<()> {
let client = NodeClient::new(&node, None);
let resp = client.get(&format!("/api/v1/bounties/{id}")).await?;
async fn cmd_show(id: String, node: String, dir: Option<PathBuf>) -> Result<()> {
let client = signed_client(&node, dir.as_deref());
let resp = client.get_authed(&format!("/api/v1/bounties/{id}")).await?;

let status = resp.status();
let body: Value = resp.json().await.unwrap_or_default();
Expand Down Expand Up @@ -462,7 +480,7 @@ mod tests {
.create_async()
.await;

cmd_list(None, None, server.url()).await.unwrap();
cmd_list(None, None, server.url(), None).await.unwrap();
}

#[tokio::test]
Expand Down Expand Up @@ -506,7 +524,7 @@ mod tests {
.create_async()
.await;

let err = cmd_show("nonexistent".to_string(), server.url())
let err = cmd_show("nonexistent".to_string(), server.url(), None)
.await
.unwrap_err();
assert!(err.to_string().contains("not found"));
Expand Down
48 changes: 33 additions & 15 deletions crates/gl/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
use anyhow::{Context, Result};
use clap::{Args, Subcommand};
use serde_json::Value;
use std::path::PathBuf;

use crate::http::NodeClient;
use crate::identity::load_keypair_from_dir;

fn signed_client(node: &str, dir: Option<&std::path::Path>) -> NodeClient {
NodeClient::new(node, load_keypair_from_dir(dir).ok())
}

#[derive(Args)]
pub struct CertArgs {
#[command(subcommand)]
Expand All @@ -23,6 +28,8 @@ pub enum CertCmd {
repo: String,
#[arg(long, default_value = "https://node.gitlawb.com", env = "GITLAWB_NODE")]
node: String,
#[arg(long)]
dir: Option<PathBuf>,
},
/// Show a specific ref certificate and verify its signature
Show {
Expand All @@ -32,28 +39,39 @@ pub enum CertCmd {
id: String,
#[arg(long, default_value = "https://node.gitlawb.com", env = "GITLAWB_NODE")]
node: String,
#[arg(long)]
dir: Option<PathBuf>,
},
}

pub async fn run(args: CertArgs) -> Result<()> {
match args.cmd {
CertCmd::List { repo, node } => cmd_list(repo, node).await,
CertCmd::Show { repo, id, node } => cmd_show(repo, id, node).await,
CertCmd::List { repo, node, dir } => cmd_list(repo, node, dir).await,
CertCmd::Show {
repo,
id,
node,
dir,
} => cmd_show(repo, id, node, dir).await,
}
}

/// Resolve "repo" into (owner, name) using the caller's DID when no slash is given.
async fn resolve_repo(repo: &str, node: &str) -> Result<(String, String)> {
async fn resolve_repo(
repo: &str,
node: &str,
dir: Option<&std::path::Path>,
) -> Result<(String, String)> {
if let Some((owner, name)) = repo.split_once('/') {
Ok((owner.to_string(), name.to_string()))
} else {
let short = if let Ok(kp) = load_keypair_from_dir(None) {
let short = if let Ok(kp) = load_keypair_from_dir(dir) {
let did = kp.did().to_string();
did.split(':').next_back().unwrap_or(&did).to_string()
} else {
let client = NodeClient::new(node, None);
let client = signed_client(node, dir);
let info: Value = client
.get("/")
.get_authed("/")
.await?
.json()
.await
Expand All @@ -65,13 +83,13 @@ async fn resolve_repo(repo: &str, node: &str) -> Result<(String, String)> {
}
}

async fn cmd_list(repo: String, node: String) -> Result<()> {
let (owner, name) = resolve_repo(&repo, &node).await?;
async fn cmd_list(repo: String, node: String, dir: Option<PathBuf>) -> Result<()> {
let (owner, name) = resolve_repo(&repo, &node, dir.as_deref()).await?;

let client = NodeClient::new(&node, None);
let client = signed_client(&node, dir.as_deref());
let path = format!("/api/v1/repos/{owner}/{name}/certs");
let resp: Value = client
.get(&path)
.get_authed(&path)
.await?
.json()
.await
Expand All @@ -96,16 +114,16 @@ async fn cmd_list(repo: String, node: String) -> Result<()> {
Ok(())
}

async fn cmd_show(repo: String, id: String, node: String) -> Result<()> {
let (owner, name) = resolve_repo(&repo, &node).await?;
async fn cmd_show(repo: String, id: String, node: String, dir: Option<PathBuf>) -> Result<()> {
let (owner, name) = resolve_repo(&repo, &node, dir.as_deref()).await?;

let client = NodeClient::new(&node, None);
let client = signed_client(&node, dir.as_deref());
let id = resolve_cert_id(&client, &owner, &name, &id).await?;

// Fetch the certificate
let path = format!("/api/v1/repos/{owner}/{name}/certs/{id}");
let resp = client
.get(&path)
.get_authed(&path)
.await?
.error_for_status()
.context("certificate not found")?;
Expand Down Expand Up @@ -170,7 +188,7 @@ async fn resolve_cert_id(client: &NodeClient, owner: &str, name: &str, id: &str)

let path = format!("/api/v1/repos/{owner}/{name}/certs");
let resp: Value = client
.get(&path)
.get_authed(&path)
.await?
.error_for_status()
.context("failed to list certificates")?
Expand Down
9 changes: 9 additions & 0 deletions crates/gl/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ impl NodeClient {
.with_context(|| format!("GET {url}"))
}

/// GET that signs when a keypair is available; falls back to unsigned for public repos.
pub async fn get_authed(&self, path: &str) -> Result<reqwest::Response> {
if self.keypair.is_some() {
self.get_signed(path).await
} else {
self.get(path).await
}
}

/// GET with RFC 9421 HTTP Signature auth, for owner-only read endpoints.
/// Signs over the empty body (same shape the node verifies for signed reads).
pub async fn get_signed(&self, path: &str) -> Result<reqwest::Response> {
Expand Down
Loading
Loading