mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
rngit: refuse create, fork, and mirror from a blocked identity
This commit is contained in:
1 parent
e3f7387c20
commit
213d40afa2
3 files changed
+19
-3
No files matched your search
@@ -377,6 +377,14 @@ fn handle_remote_clone(
|
||||
let Some(path_value) = get(map, &Value::from(IDX_REPOSITORY)) else {
|
||||
return Some(status(RES_INVALID_REQ, "No repository specified"));
|
||||
};
|
||||
// Differs from `_handle_remote_clone` (`server.py`), which admits a blocked identity.
|
||||
if repos
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.is_blocked(hash)
|
||||
{
|
||||
return Some(status(RES_NOT_FOUND, "Not found"));
|
||||
}
|
||||
let source = get(map, &Value::from("source"));
|
||||
if !source.is_some_and(truthy) {
|
||||
return Some(status(RES_INVALID_REQ, "No source specified"));
|
||||
|
||||
@@ -161,7 +161,7 @@ pub fn identity_text(identity: Option<&[u8; 16]>) -> String {
|
||||
|
||||
/// `log_request` (`server.py`).
|
||||
pub fn log_request(repos: &Repositories, message: &str, identity: Option<&[u8; 16]>) {
|
||||
if identity.is_some_and(|h| repos.blocked.iter().any(|b| b.as_slice() == h)) {
|
||||
if identity.is_some_and(|h| repos.is_blocked(h)) {
|
||||
tracing::debug!("Blocked: {message}");
|
||||
} else {
|
||||
tracing::debug!("{message}");
|
||||
@@ -594,7 +594,6 @@ pub fn handle_delete(
|
||||
pub(super) const REPO_CREATE_PERMS_TEMPLATE: &str = "adm:{IDENTITY_HASH}";
|
||||
|
||||
/// `handle_create` (`server.py`). `None` sends no response.
|
||||
/// Group permissions are checked without the blocklist, as upstream does.
|
||||
pub fn handle_create(
|
||||
repos: &std::sync::RwLock<Repositories>,
|
||||
identity: Option<&[u8; 16]>,
|
||||
@@ -612,6 +611,10 @@ pub fn handle_create(
|
||||
Ok(Some(parsed)) => parsed,
|
||||
};
|
||||
let hash = identity.expect("checked");
|
||||
// Differs from `handle_create` (`server.py`), which admits a blocked identity.
|
||||
if repos.is_blocked(hash) {
|
||||
return Some(status(RES_NOT_FOUND, "Not found"));
|
||||
}
|
||||
let Some((group, repo)) = path.filter(|(g, r)| !g.is_empty() && !r.is_empty()) else {
|
||||
return Some(status(RES_INVALID_REQ, "Invalid request"));
|
||||
};
|
||||
|
||||
@@ -199,6 +199,11 @@ impl Repositories {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Whether `blocked_identities` names this identity.
|
||||
pub fn is_blocked(&self, hash: &[u8; 16]) -> bool {
|
||||
self.blocked.iter().any(|b| b.as_slice() == hash)
|
||||
}
|
||||
|
||||
/// `resolve_permission` (`server.py`), the only resolver that
|
||||
/// checks the blocklist.
|
||||
pub fn resolve_permission(
|
||||
@@ -208,7 +213,7 @@ impl Repositories {
|
||||
repository: &str,
|
||||
perm: Perm,
|
||||
) -> bool {
|
||||
if self.blocked.iter().any(|b| b.as_slice() == hash) {
|
||||
if self.is_blocked(hash) {
|
||||
return false;
|
||||
}
|
||||
let Some(g) = self.groups.get(group) else {
|
||||
|
||||
Reference in new issue
Block a user