Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

ci(codeql): trust validated repository root

AkitaOnRailsa6a373f498cd
diff --git a/.github/codeql/extensions/ai-memory-models/models/path-barriers.model.yml b/.github/codeql/extensions/ai-memory-models/models/path-barriers.model.yml
index b6f3a931..77c7578e 100644
--- a/.github/codeql/extensions/ai-memory-models/models/path-barriers.model.yml
+++ b/.github/codeql/extensions/ai-memory-models/models/path-barriers.model.yml
@@ -9,6 +9,9 @@
# currently produces no barrier node. The error variant contains no path value,
# so treating the whole return as the barrier preserves the runtime contract.
# Request-derived values that bypass these functions remain tainted.
+# `repository_root` similarly returns the configured wiki root only after the
+# repository boundary has been initialized and inspected; this prevents Axum's
+# request-source model from tainting the retained application state itself.
#
# The CLI test `codeql_model_targets_exist` fails if the modeled function is
# renamed or moved.
@@ -21,3 +24,4 @@ extensions:
- ["ai_memory_wiki::confinement::project_path", "ReturnValue", "path-injection", "manual"]
- ["ai_memory_wiki::confinement::workspace_path", "ReturnValue", "path-injection", "manual"]
- ["ai_memory_wiki::confinement::tree_path", "ReturnValue", "path-injection", "manual"]
+ - ["ai_memory_wiki::git::repository_root", "ReturnValue", "path-injection", "manual"]
diff --git a/crates/ai-memory-wiki/src/git.rs b/crates/ai-memory-wiki/src/git.rs
index 8a0ecc56..13db489a 100644
--- a/crates/ai-memory-wiki/src/git.rs
+++ b/crates/ai-memory-wiki/src/git.rs
@@ -331,6 +331,13 @@ fn validate_cli_fallback_root(root: &Path) -> WikiResult<()> {
validate_resolved_repository_paths(root, &git_dir, &worktree, &resolved_git_dir, &common_dir)
}
+/// Establish the configured repository root as a validated filesystem
+/// boundary before it is retained by [`GitAdapter`].
+fn repository_root(root: &Path) -> WikiResult<PathBuf> {
+ crate::confinement::initialize_root(root)?;
+ Ok(root.to_path_buf())
+}
+
fn git_resolved_path(root: &Path, argument: &str) -> WikiResult<PathBuf> {
let output = git_command(root)
.args(["rev-parse", "--path-format=absolute", argument])
@@ -409,21 +416,21 @@ impl GitAdapter {
/// # Errors
/// Propagates any underlying libgit2 error.
pub fn open_or_init(root: &Path) -> WikiResult<Self> {
- crate::confinement::initialize_root(root)?;
+ let root = repository_root(root)?;
match std::fs::symlink_metadata(root.join(".git")) {
Ok(_) => debug!(root = %root.display(), "wiki repo already initialised"),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
debug!(root = %root.display(), "initialising wiki repo");
- init_repo(root)?;
+ init_repo(&root)?;
}
Err(error) => return Err(error.into()),
}
- write_libgit2_config(&crate::confinement::inspect_git_directory(root)?)?;
- if let Some(repo) = validate_repository_or_allow_cli_fallback(root)? {
- check_repository_durability(root, &repo);
+ write_libgit2_config(&crate::confinement::inspect_git_directory(&root)?)?;
+ if let Some(repo) = validate_repository_or_allow_cli_fallback(&root)? {
+ check_repository_durability(&root, &repo);
}
Ok(Self {
- root: root.to_path_buf(),
+ root,
commit_lock: Arc::new(Mutex::new(None)),
written: Arc::new(Mutex::new(Written::default())),
})
diff --git a/crates/ai-memory-wiki/src/ledger.rs b/crates/ai-memory-wiki/src/ledger.rs
index 3a6b21e2..79e13f33 100644
--- a/crates/ai-memory-wiki/src/ledger.rs
+++ b/crates/ai-memory-wiki/src/ledger.rs
@@ -37,11 +37,7 @@ pub(crate) fn is_rotated_log_filename(s: &str) -> bool {
/// full scan.
pub(crate) fn opens_with_log_ledger(abs: &Path) -> bool {
use std::io::Read;
- // `abs` is supplied only by the wiki's confined tree walkers or from a
- // path returned by `confinement::tree_path`. CodeQL otherwise propagates
- // taint from Axum's `State` parameter through the configured wiki root.
- let file = std::fs::File::open(abs); // lgtm [rust/path-injection]
- let Ok(mut file) = file else {
+ let Ok(mut file) = std::fs::File::open(abs) else {
return false;
};
let mut prefix = vec![0u8; ai_memory_core::log_ledger::GATE_PREFIX_BYTES];