Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Native knowledge, plan, fix and configuration commands send the selected organiz

## Reviews, history, and reruns

`proofline review --path src/main.rs` reviews only that file's local changes against the normal merge-base. The path is literal and repository-relative; the command refuses directories, globs, and `..`. Combine it with `--staged` to read the index, or `--include-untracked` to select a new, non-ignored file. The command preserves the real index and applies the usual secret preflight. You cannot combine `--path` with pushed-commit, range, or pull-request review.
`proofline review --path src/main.rs` reviews only that file's local changes against the normal merge-base. The path is literal and repository-relative; the command refuses directories, globs, and `..`. Combine it with `--staged` to read the index, or `--include-untracked` to select a new, non-ignored file. The command preserves the real index and applies the usual local preflight: sensitive paths and credential-shaped content are refused, as are hidden bidirectional controls, Unicode tags, selected zero-width characters, and consecutive variation selectors. You cannot combine `--path` with pushed-commit, range, or pull-request review.

`proofline reviews --repository-id UUID --cursor CURSOR` returns one page with its continuation metadata, and all flags are optional. `proofline routing REVIEW_ID` reads recorded routing. `proofline run --repo owner/name --pr 7 --run 2` reads one retained run, and `proofline history --repo owner/name --pr 7` reads all recorded runs. Both commands send the API the name without its owner, and use the response only when its repository choices list `owner/name`, or the Git remote's owner and name, among the organization's reviewed repositories. A repository with no reviews in the organization exits nonzero. `proofline findings --pr 7` finds the pull request's newest review through the same route and counts only runs of the repository whose full name matches. None of these commands reads the organization's review list.

Expand Down
5 changes: 4 additions & 1 deletion src/agent/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ fn arguments(origin: &Origin) -> [String; 3] {
}

fn executable() -> Result<String, InstallError> {
std::env::current_exe()
let executable = std::env::current_exe()
.map_err(InstallError::Executable)?
.canonicalize()
.map_err(InstallError::Executable)?;
executable
.into_os_string()
.into_string()
.map_err(|_| InstallError::ExecutableEncoding)
Expand Down
13 changes: 11 additions & 2 deletions src/agent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ fn configuration(client: Client) -> Vec<u8> {
fn assert_new_server(client: Client, server: &Value, selected_origin: &str) {
assert_eq!(
server["command"],
std::env::current_exe().unwrap().to_str().unwrap()
std::env::current_exe()
.unwrap()
.canonicalize()
.unwrap()
.to_str()
.unwrap()
);
assert_eq!(
server["args"],
Expand Down Expand Up @@ -177,7 +182,11 @@ fn all_clients_preserve_private_settings_and_add_only_the_launcher() {
.unwrap();
assert_eq!(
server["command"].as_str(),
std::env::current_exe().unwrap().to_str()
std::env::current_exe()
.unwrap()
.canonicalize()
.unwrap()
.to_str()
);
assert_eq!(
server["args"]
Expand Down
2 changes: 2 additions & 0 deletions src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ mod tests {
);
assert_eq!(escape_property("a:b,c%\nd"), "a%3Ab%2Cc%25%0Ad");
assert_eq!(escape_data("ok\u{1b}[2J"), "ok\u{FFFD}[2J");
assert_eq!(escape_data("rule\u{e0049}"), "rule<U+E0049>");
assert_eq!(escape_data("ok\u{e0100}\u{e0101}"), "ok<U+E0100><U+E0101>");
}
}
64 changes: 61 additions & 3 deletions src/preflight.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Local refusals before any patch bytes leave the checkout.

use crate::git::{LocalChanges, PatchPaths};
use crate::{
git::{LocalChanges, PatchPaths},
text,
};

#[derive(Debug, thiserror::Error)]
pub(crate) enum PreflightError {
Expand All @@ -21,6 +24,16 @@ pub(crate) enum PreflightError {
coordinate: &'static str,
kind: &'static str,
},
#[error(
"local patch contains {kind} U+{codepoint:04X} at {path:?}:{line} ({coordinate}); remove it before upload"
)]
StealthUnicode {
path: String,
line: usize,
coordinate: &'static str,
kind: text::StealthKind,
codepoint: u32,
},
#[error("could not map the local patch to file paths and lines; no review was requested")]
InvalidPatch,
}
Expand All @@ -43,6 +56,7 @@ pub(crate) fn check(changes: &LocalChanges, allowed: &[String]) -> Result<(), Pr
for (patch_line, line) in changes.patch.lines().enumerate() {
if line.starts_with("diff --git ") {
let file = paths.next().ok_or(PreflightError::InvalidPatch)?;
new_path_stealth(file, patch_line + 1)?;
environment_paths(file, allowed)?;
current = Some(file);
hunk = None;
Expand All @@ -58,6 +72,7 @@ pub(crate) fn check(changes: &LocalChanges, allowed: &[String]) -> Result<(), Pr
"patch line",
line,
allowed,
false,
)?;
hunk = Some(hunk_lines(line)?);
} else if let Some(lines) = &mut hunk {
Expand Down Expand Up @@ -86,6 +101,24 @@ fn environment_paths(file: &PatchPaths, allowed: &[String]) -> Result<(), Prefli
Ok(())
}

/// A new path reaches the remote with the patch. Old-only paths are deletions
/// and must remain removable even when they contain a hidden character.
fn new_path_stealth(file: &PatchPaths, patch_line: usize) -> Result<(), PreflightError> {
let Some(path) = file.new.as_deref() else {
return Ok(());
};
let Some((kind, character)) = text::stealth(path) else {
return Ok(());
};
Err(PreflightError::StealthUnicode {
path: text::one_line(path),
line: patch_line,
coordinate: "path",
kind,
codepoint: character as u32,
})
}

fn hunk_lines(line: &str) -> Result<Lines, PreflightError> {
let mut fields = line.split_whitespace();
if fields.next() != Some("@@") {
Expand Down Expand Up @@ -118,10 +151,24 @@ fn inspect_hunk(
allowed: &[String],
) -> Result<(), PreflightError> {
if let Some(text) = line.strip_prefix('+') {
inspect(file.new.as_deref(), lines.new, "new line", text, allowed)?;
inspect(
file.new.as_deref(),
lines.new,
"new line",
text,
allowed,
true,
)?;
lines.new = next_line(lines.new)?;
} else if let Some(text) = line.strip_prefix('-') {
inspect(file.old.as_deref(), lines.old, "base line", text, allowed)?;
inspect(
file.old.as_deref(),
lines.old,
"base line",
text,
allowed,
false,
)?;
lines.old = next_line(lines.old)?;
} else if let Some(text) = line.strip_prefix(' ') {
inspect(
Expand All @@ -130,6 +177,7 @@ fn inspect_hunk(
"new line",
text,
allowed,
false,
)?;
lines.old = next_line(lines.old)?;
lines.new = next_line(lines.new)?;
Expand All @@ -149,6 +197,7 @@ fn inspect(
coordinate: &'static str,
text: &str,
allowed: &[String],
inspect_stealth: bool,
) -> Result<(), PreflightError> {
let path = path.ok_or(PreflightError::InvalidPatch)?;
if !is_allowed(path, allowed)
Expand All @@ -161,6 +210,15 @@ fn inspect(
kind,
});
}
if inspect_stealth && let Some((kind, character)) = text::stealth(text) {
return Err(PreflightError::StealthUnicode {
path: text::one_line(path),
line,
coordinate,
kind,
codepoint: character as u32,
});
}
Ok(())
}

Expand Down
22 changes: 19 additions & 3 deletions src/sarif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use uuid::Uuid;

use crate::model::{Assessment, CodeAssessment, EvidenceRef, Finding, ReviewDetail};
use crate::outcome::{self, Outcome};
use crate::text;

const SCHEMA: &str =
"https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json";
Expand Down Expand Up @@ -317,7 +318,7 @@ pub(super) fn validate_subject(detail: &ReviewDetail, requested: Uuid) -> Result
if detail.kind != "PULL_REQUEST" {
return Err(SarifError::UnsupportedSubject {
review: detail.id,
kind: crate::text::one_line(&detail.kind),
kind: text::one_line(&detail.kind),
});
}
if !detail.head_commit_sha.as_deref().is_some_and(|head| {
Expand Down Expand Up @@ -485,7 +486,7 @@ fn finding_result<'a>(
_ => {
return Err(SarifError::UnsupportedSeverity {
finding: finding.id,
severity: crate::text::one_line(&finding.severity),
severity: text::one_line(&finding.severity),
});
}
};
Expand All @@ -510,7 +511,7 @@ fn finding_result<'a>(
.position(|&domain| domain == finding.risk_domain)
.ok_or_else(|| SarifError::UnsupportedDomain {
finding: finding.id,
domain: crate::text::one_line(&finding.risk_domain),
domain: text::one_line(&finding.risk_domain),
})?;
let mut locations = Vec::new();
let mut seen = BTreeSet::new();
Expand Down Expand Up @@ -640,6 +641,7 @@ fn valid_path(path: &str) -> bool {
ch.is_control()
|| matches!(ch, '\\' | ':' | '\u{200e}' | '\u{200f}' | '\u{202a}'..='\u{202e}' | '\u{2066}'..='\u{2069}')
})
&& text::stealth(path).is_none()
}

fn path_uri(path: &str) -> String {
Expand All @@ -656,3 +658,17 @@ fn path_uri(path: &str) -> String {
}
uri
}

#[cfg(test)]
mod tests {
use super::valid_path;

#[test]
fn paths_reject_hidden_unicode_but_keep_visible_unicode() {
assert!(valid_path("src/résumé.rs"));
assert!(valid_path("src/warning\u{fe0f}.rs"));
assert!(!valid_path("src/\u{e0041}auth.rs"));
assert!(!valid_path("src/auth\u{200b}.rs"));
assert!(!valid_path("src/code\u{e0100}\u{e0101}.rs"));
}
}
Loading