The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix(runner): preserve credential content in document saves (#14937)
Dotta9786f6df560a
diff --git a/doc/SPEC-implementation.md b/doc/SPEC-implementation.mdindex 051dc607cb..e79ebaa327 100644--- a/doc/SPEC-implementation.md+++ b/doc/SPEC-implementation.md@@ -1533,6 +1533,7 @@ Required UX behaviors:- store only hashed agent API keys- redact secrets in logs (`adapter_config`, auth headers, env vars)+- forward authorized semantic tool arguments unchanged, including credential-bearing document and instruction content; the provider harness owns credential-content policy, and diagnostic redaction must not act as a save or execution gate- CSRF protection for board session endpoints- rate limit auth and key-management endpoints- strict company boundary checks on every entity fetch/mutationdiff --git a/packages/adapter-utils/src/command-redaction.test.ts b/packages/adapter-utils/src/command-redaction.test.tsindex 68ea18478e..4af35d09df 100644--- a/packages/adapter-utils/src/command-redaction.test.ts+++ b/packages/adapter-utils/src/command-redaction.test.ts@@ -1,10 +1,31 @@import { describe, expect, it } from "vitest";++describe("explicit diagnostic credential forms", () => {+ it("masks suffixed CLI options and encoded JSON headers with whitespace", () => {+ const jwt = `${Buffer.from(' {"alg":"HS256","typ":"JWT"}').toString("base64url")}.abcdefghijk.abcdefghijkl`;+ expect(redactCommandText("tool --api-key-prod sensitivevalue --token-policy readable"))+ .not.toContain("sensitivevalue");+ expect(redactCommandText(`provider ${jwt}`)).not.toContain(jwt);+ expect(redactCommandText("plan.security.credentials.md")).toBe("plan.security.credentials.md");+ });+});import {REDACTED_COMMAND_TEXT_VALUE,redactDiagnosticText,+ redactCommandText,} from "./command-redaction.js";describe("redactDiagnosticText", () => {+ it("preserves credential metadata and dotted identifiers", () => {+ for (const text of [+ '"tokenBudget":4000 --token-budget 4000 SECRET_STORAGE=vault',+ '{"credentialHandling":"harness","authorizationRequired":true}',+ "executor.customTools.integrations.list deployment.credentials.example.md api.openai.com",+ "Use a private key and secret manager with credential handling.",+ "Use bearer tokens and bearer authentication.",+ ]) expect(redactDiagnosticText(text)).toBe(text);+ });+it("redacts a JSON secret field value", () => {const input = '{"token":"opaque-value","status":"error"}';const output = redactDiagnosticText(input);diff --git a/packages/adapter-utils/src/command-redaction.ts b/packages/adapter-utils/src/command-redaction.tsindex d922367c1d..465255caf4 100644--- a/packages/adapter-utils/src/command-redaction.ts+++ b/packages/adapter-utils/src/command-redaction.ts@@ -1,7 +1,7 @@export const REDACTED_COMMAND_TEXT_VALUE = "***REDACTED***";-// These exact public Executor helper addresses resemble dotted bearer tokens.-// Do not exempt arbitrary provider paths, prefixes, or user-defined selectors.+// Public Executor helper addresses retained for callers of this predicate.+// Dotted addresses alone do not meet the JWT credential heuristic.const PUBLIC_EXECUTOR_TOOL_SELECTORS = new Set(["executor.coreTools.integrations.list","executor.coreTools.connections.list",@@ -11,7 +11,7 @@ export function isPublicExecutorToolSelector(value: string): boolean {return PUBLIC_EXECUTOR_TOOL_SELECTORS.has(value);}-const SECRET_NAME_PATTERN = String.raw`[A-Za-z0-9_-]*(?:api[-_]?key|(?:access[-_]?|auth[-_]?)?token|token|authorization|bearer|secret|passwd|password|credential|jwt|private[-_]?key|cookie|connectionstring)[A-Za-z0-9_-]*`;+const SECRET_NAME_PATTERN = String.raw`[A-Za-z0-9_-]*(?:api[-_]?key|(?:access[-_]?|auth[-_]?)?token|token|authorization(?:[-_]?code)?|bearer|secrets?|passwd|passwords?|credentials?|jwt|private[-_]?key|cookie|connectionstring)(?:[-_]?(?:value|header|prod(?:uction)?|dev(?:elopment)?|test|staging|primary|secondary))*`;const COMMAND_CLI_SECRET_OPTION_RE = new RegExp(String.raw`(\B-{1,2}${SECRET_NAME_PATTERN}(?:\s+|=)(["']?))[^\s"'` +@@ -32,7 +32,20 @@ const COMMAND_AUTHORIZATION_BEARER_RE =const COMMAND_OPENAI_KEY_RE = /\bsk-[A-Za-z0-9_-]{12,}\b/g;const COMMAND_GITHUB_TOKEN_RE = /\bgh[pousr]_[A-Za-z0-9_]{20,}\b/g;const COMMAND_JWT_RE =- /\b[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}(?:\.[A-Za-z0-9_-]{8,})?\b/g;+ /\b[A-Za-z0-9_-]{8,}(?:\.[A-Za-z0-9_-]{8,}){2}(?:\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,})?\b/g;+/** Recognize encoded JSON headers, without treating dotted identifiers as tokens. */+export function looksLikeCredentialJwt(value: string): boolean {+ const segments = value.split(".");+ if (![3, 5].includes(segments.length) || segments.some((part) => !/^[A-Za-z0-9_-]{8,}$/.test(part))) return false;+ if (segments[0].startsWith("eyJ")) return true;+ try {+ const header = JSON.parse(atob(segments[0].replace(/-/g, "+").replace(/_/g, "/")));+ return typeof header === "object" && header !== null && typeof header.alg === "string";+ } catch {+ return false;+ }+}+const COMMAND_SECRET_HINTS = ["api","key",@@ -87,12 +100,7 @@ export function redactCommandText().replace(COMMAND_OPENAI_KEY_RE, redactedValue).replace(COMMAND_GITHUB_TOKEN_RE, redactedValue)- .replace(COMMAND_JWT_RE, (match, offset: number, source: string) => {- // The JWT heuristic may match only the first three segments; inspect the- // complete address so a longer secret sharing a prefix stays redacted.- const address = source.slice(offset).match(/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*/)?.[0];- return address && isPublicExecutorToolSelector(address) ? match : redactedValue;- });+ .replace(COMMAND_JWT_RE, (match) => looksLikeCredentialJwt(match) ? redactedValue : match);}// A JSON secret field is a key/value pair such as `"token":"opaque-value"`. Thediff --git a/packages/paperclip-runner/README.md b/packages/paperclip-runner/README.mdindex 27913b20dd..9443b19b77 100644--- a/packages/paperclip-runner/README.md+++ b/packages/paperclip-runner/README.md@@ -139,7 +139,13 @@ tool, input, permission, and terminal events require the exact active binding.A package-local payload boundary decodes events only after that scope check. Itvalidates control identities, terminal status, question sets, and the admittedruntime event types and bounded fields. It redacts diagnostic and retained-event values again before they can enter provider state.+event values again before they can enter provider state. Authoritative semantic+tool arguments are validated for transport bounds and forwarded unchanged,+including credential-bearing document and instruction content. The provider+harness owns credential policy; redaction of logs and audit previews must not+reject or rewrite execution arguments. Diagnostic detection requires explicit+credential fields/assignments or recognizable key, Bearer, JWT, or PEM formats,+not ordinary prose such as "credential handling" or dotted filenames.Validated ACPX runtime events normalize into the same provider-neutral activityfamilies as the direct Codex transport. Reasoning contents stay private. Tooldiff --git a/packages/paperclip-runner/runner/crates/runner-core/src/acpx_event_payload.rs b/packages/paperclip-runner/runner/crates/runner-core/src/acpx_event_payload.rsindex 677f3d836e..1aa90973c8 100644--- a/packages/paperclip-runner/runner/crates/runner-core/src/acpx_event_payload.rs+++ b/packages/paperclip-runner/runner/crates/runner-core/src/acpx_event_payload.rs@@ -6,7 +6,7 @@ use serde_json::Value;use crate::acpx_event_scope::AcpxEventScope;use crate::acpx_sidecar_transport::AcpxSidecarEvent;use crate::durable::{- redact_sensitive_text_values, redact_text, sanitize_semantic_tool_input, sanitize_value,+ redact_sensitive_text_values, redact_text, sanitize_value, validate_semantic_tool_input,};use crate::generated_acpx_sidecar_contract::{classify_generated_acpx_tool_operation, GeneratedAcpxSidecarEventType,@@ -147,7 +147,7 @@ pub fn decode_acpx_event(// the event feed. Use the same declared-prose policy as native// semantic_tool.input before any generic diagnostic scrub can// irreversibly change the task's requirements.- let safe_input = sanitize_semantic_tool_input(&operation_id, &input)+ let safe_input = validate_semantic_tool_input(&operation_id, &input).map_err(|error| LocalRunnerError::invalid(error.to_string()))?;Ok(AcpxEventPayload::ToolCalled {call_id: required_id(&event.payload, "callId", "tool call")?,diff --git a/packages/paperclip-runner/runner/crates/runner-core/src/durable/mod.rs b/packages/paperclip-runner/runner/crates/runner-core/src/durable/mod.rsindex 24418539af..7cbe493ba0 100644--- a/packages/paperclip-runner/runner/crates/runner-core/src/durable/mod.rs+++ b/packages/paperclip-runner/runner/crates/runner-core/src/durable/mod.rs@@ -17,7 +17,7 @@ pub use runner::{};pub(crate) use state::{create_private_temporary_file, open_private_regular_file, redact_sensitive_text_values,- redact_text, sanitize_semantic_tool_input, sanitize_value, verify_private_directory,+ redact_text, sanitize_value, validate_semantic_tool_input, verify_private_directory,};pub use state::{Command, CommandDisposition, DurableState, DurableStateStore, EventPriority,diff --git a/packages/paperclip-runner/runner/crates/runner-core/src/durable/state.rs b/packages/paperclip-runner/runner/crates/runner-core/src/durable/state.rsindex 004eb555ea..894a00176c 100644--- a/packages/paperclip-runner/runner/crates/runner-core/src/durable/state.rs+++ b/packages/paperclip-runner/runner/crates/runner-core/src/durable/state.rs@@ -7,6 +7,7 @@ use std::time::{SystemTime, UNIX_EPOCH};#[cfg(unix)]use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};+use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _};use serde::{Deserialize, Serialize};use serde_json::{json, Value};use sha2::{Digest, Sha256};@@ -526,16 +527,20 @@ impl DurableState {}validate_semantic_tool_input_digest(event_type.as_str(), &payload)?;- let sanitized_payload = sanitize_value(&payload);+ let sanitized_payload = preserve_bounded_display_content(+ event_type.as_str(),+ &payload,+ sanitize_value(&payload),+ )?;+ // Restore authoritative tool arguments before checking protocol identities.+ // Their contents are execution data, not a redacted diagnostic preview.+ let sanitized_payload =+ finalize_semantic_tool_input_payload(event_type.as_str(), &payload, sanitized_payload)?;if durable_semantics_changed_by_sanitization(&payload, &sanitized_payload) {return Err(DurableRunnerError::invalid("durable identity or validation semantics contain credential-shaped material",));}- let sanitized_payload =- preserve_bounded_display_content(event_type.as_str(), &payload, sanitized_payload)?;- let sanitized_payload =- finalize_semantic_tool_input_payload(event_type.as_str(), &payload, sanitized_payload)?;let source_seq = self.next_source_seq;let emitted_at = current_timestamp()?;@@ -1513,8 +1518,24 @@ fn sensitive_key(key: &str, value: &Value) -> bool {) {return !value.is_number();}+ let credential_name = [+ "value",+ "header",+ "production",+ "prod",+ "development",+ "dev",+ "test",+ "staging",+ "primary",+ "secondary",+ ]+ .iter()+ .find_map(|suffix| normalized.strip_suffix(suffix))+ .unwrap_or(&normalized);["authorization",+ "authorizationcode","bearer","browsercode","cookie",@@ -1522,16 +1543,19 @@ fn sensitive_key(key: &str, value: &Value) -> bool {"jwt","loginurl","password",+ "passwords","passwd","privatekey","secret",+ "secrets","token","ticket","apikey","credential",+ "credentials",].iter()- .any(|needle| normalized.contains(needle))+ .any(|needle| credential_name.ends_with(needle))}fn protocol_authorization_boundary(key: &str, value: &Value) -> bool {@@ -1689,7 +1713,7 @@ fn preserve_bounded_display_content(Ok(sanitized)}-pub(crate) fn sanitize_semantic_tool_input(+pub(crate) fn validate_semantic_tool_input(operation_id: &str,input: &Value,) -> Result<Value, DurableRunnerError> {@@ -1697,8 +1721,8 @@ pub(crate) fn sanitize_semantic_tool_input(// redaction must never turn it into a different, apparently valid write.// Hex-encoded authenticated frames double JSON bytes. Reserve envelope// space below the 1 MiB wire cap before any effect can start.- // Enforce the transport envelope before dispatch, and reject content that- // cannot cross its credential policy instead of silently rewriting it.+ // Credential policy belongs to the harness. Only transport bounds are+ // enforced here; executed arguments must retain their original bytes.if serde_json::to_vec(input).map_err(|_| DurableRunnerError::invalid("semantic tool input is not serializable"))?.len()@@ -1708,25 +1732,6 @@ pub(crate) fn sanitize_semantic_tool_input("semantic tool input exceeds the 480 KiB encrypted transport limit",));}- let mut checked = sanitize_bounded_display_value(input);- let prose_fields: &[&str] = match operation_id {- "set_task_title" => &["title"],- "create_task" => &["title", "description", "initialPlan"],- "create_project" => &["name", "description"],- "write_document" => &["title", "body", "changeSummary"],- "update_agent_instructions" => &["content"],- _ => &[],- };- if let Some(object) = checked.as_object_mut() {- for field in prose_fields {- if let Some(text) = input.get(*field).and_then(Value::as_str) {- object.insert(- (*field).to_owned(),- Value::String(redact_sensitive_text_values_with_context(text, true)),- );- }- }- }if matches!(operation_id, "paperclip_finish" | "paperclip_block")&& input.get("summary")@@ -1737,11 +1742,6 @@ pub(crate) fn sanitize_semantic_tool_input("semantic completion summary exceeds the 12,000 character limit",));}- if checked != *input {- return Err(DurableRunnerError::invalid(- "semantic tool input contains credential material; refusing to execute altered arguments",- ));- }Ok(input.clone())}@@ -1768,7 +1768,7 @@ fn finalize_semantic_tool_input_payload(let Some(original_input) = original_tool.get("input") else {return Ok(sanitized);};- let finalized_input = sanitize_semantic_tool_input(operation_id, original_input)?;+ let finalized_input = validate_semantic_tool_input(operation_id, original_input)?;let Some(sanitized_tool) = sanitized.get_mut("semantic_tool").and_then(Value::as_object_mut)@@ -1843,10 +1843,6 @@ pub(crate) fn redact_text(input: &str) -> String {}pub(crate) fn redact_sensitive_text_values(input: &str) -> String {- redact_sensitive_text_values_with_context(input, false)-}--fn redact_sensitive_text_values_with_context(input: &str, semantic_prose: bool) -> String {let normalized = input.to_ascii_lowercase();let bytes = normalized.as_bytes();let mut ranges: Vec<(usize, usize)> = Vec::new();@@ -2048,9 +2044,15 @@ fn redact_sensitive_text_values_with_context(input: &str, semantic_prose: bool)}let candidate_end = without_sentence_period(jwt_start, jwt_end);if candidate_end > jwt_start {- let candidate = &normalized[jwt_start..candidate_end];+ let candidate = &input[jwt_start..candidate_end];let segments = candidate.split('.').collect::<Vec<_>>();- if matches!(segments.len(), 3 | 4)+ let json_header = URL_SAFE_NO_PAD+ .decode(segments[0])+ .ok()+ .and_then(|decoded| serde_json::from_slice::<Value>(&decoded).ok())+ .is_some_and(|header| header.get("alg").is_some_and(Value::is_string));+ if (candidate.starts_with("eyJ") || json_header)+ && matches!(segments.len(), 3 | 5)&& segments.iter().all(|segment| {segment.len() >= 8&& segment.bytes().all(|value| {@@ -2094,7 +2096,27 @@ fn redact_sensitive_text_values_with_context(input: &str, semantic_prose: bool)},|quote| quoted_value_end(value_start, quote),);- if end > value_start {+ let candidate = &input[value_start..end];+ // A bare "bearer token" or "bearer authentication" is ordinary prose.+ // Quoted values, opaque formats, and long values indicate credentials;+ // explicit Authorization fields are independently redacted below.+ let prose_term = matches!(+ candidate+ .trim_end_matches(['.', ',', ';', ':', '!', '?'])+ .to_ascii_lowercase()+ .as_str(),+ "token"+ | "tokens"+ | "authentication"+ | "authorization"+ | "credential"+ | "credentials"+ | "scheme"+ | "schemes"+ | "flow"+ | "flows"+ );+ if end > value_start && (quote.is_some() || !prose_term) {ranges.push((value_start, end));}}@@ -2103,6 +2125,10 @@ fn redact_sensitive_text_values_with_context(input: &str, semantic_prose: bool)// provider diagnostic are useful context and are not secrets by themselves.let sensitive_keys = ["authorization",+ "authorization code",+ "authorization-code",+ "authorization_code",+ "authorizationcode","api key","api-key","api_key",@@ -2183,204 +2209,39 @@ fn redact_sensitive_text_values_with_context(input: &str, semantic_prose: bool)&& authorization_scheme_start + scheme.len() < bytes.len()&& bytes[authorization_scheme_start + scheme.len()].is_ascii_whitespace()});- // A small closed set of grammatical noun/count phrases is prose, not- // the diagnostic field/value pair "token opaque-value". Keep this- // exception exact: assignments, quoted/compound/CLI keys or values,- // and arbitrary words after token still use the ordinary scanners.- let token_phrase_has_lead = |lead: &str| {- normalized[..start]- .strip_suffix(lead)- .is_some_and(|before| {- before.is_empty()- || before- .as_bytes()- .last()- .is_some_and(|value| value.is_ascii_whitespace())- })- };- let token_phrase_has_tail = |tail: &str| {- normalized[separator..].starts_with(tail)- && bytes.get(separator + tail.len()).is_none_or(|value| {- value.is_ascii_whitespace()- || (matches!(value, b'.' | b',' | b';' | b')')- && bytes- .get(separator + tail.len() + 1)- .is_none_or(|next| next.is_ascii_whitespace()))- })- };- let token_phrase_follows_list_delimiter = || {- let before = &normalized[..start];- start == 0- || [", ", "; ", ": ", "\n", "- "]- .iter()- .any(|delimiter| before.ends_with(delimiter))- };- let has_hyphenated_count_lead = token_phrase_has_lead("one-");- // A bare token reference in declared mutation prose can be an output- // requirement. Auth/access/session context, explicit assignment,- // quoted credentials and CLI/compound names remain credential pairs.- // Known key/JWT/Bearer values are independently scrubbed above.- let is_semantic_token_reference = semantic_prose- && key == "token"- && !key_is_compound- && whitespace_start == start + key.len()- && separator > whitespace_start- && !has_assignment_separator- && bytes[whitespace_start..separator]- .iter()- .all(|value| matches!(value, b' ' | b'\t'))- && quoted_value_start(separator).1.is_none()- && ![- "auth ",- "authentication ",- "authorization ",- "access ",- "refresh ",- "session ",- "api ",- "security ",- "secret ",- "credential ",- "bearer ",- ]- .iter()- .any(|lead| token_phrase_has_lead(lead));- // Maintenance prose uses a closed vocabulary, including common task- // artifacts and environment qualifiers. Validate the entire suffix:- // recognizing only the first noun could hide an opaque credential after- // it. Unknown words, punctuation, assignments and CLI forms still fail- // closed. Known credential formats also use the independent scanners.- let is_semantic_key_maintenance = semantic_prose- && key == "api key"- && !key_is_compound- && (start == 0 || bytes[start - 1].is_ascii_whitespace())- && whitespace_start == start + key.len()- && separator > whitespace_start- && !has_assignment_separator- && bytes[whitespace_start..separator]- .iter()- .all(|value| matches!(value, b' ' | b'\t'))- && ["rotation", "replacement", "renewal", "expiration"]- .iter()- .any(|noun| {- normalized[separator..]- .strip_prefix(noun)- .is_some_and(|suffix| {- (suffix.is_empty() || suffix.starts_with(' ') || suffix == ".")- && !suffix.contains(['\n', '\r', '\t'])- && suffix- .strip_suffix('.')- .unwrap_or(suffix)- .split(' ')- .filter(|word| !word.is_empty())- .all(|word| {- matches!(- word,- "a" | "an"- | "the"- | "for"- | "in"- | "of"- | "and"- | "with"- | "checklist"- | "handover"- | "plan"- | "guide"- | "schedule"- | "steps"- | "staging"- | "production"- | "development"- | "test"- | "expired"- | "new"- | "old"- | "safe"- | "secure"- | "short"- | "internal"- | "teammate"- | "routine"- | "maintenance"- | "service"- | "access"- | "api"- | "key"- | "keys"- | "rotation"- | "replacement"- | "renewal"- | "expiration"- )- })- })- });- let is_benign_token_noun_phrase = key == "token"- && (!key_is_compound || has_hyphenated_count_lead)- && whitespace_start == start + key.len()- && !has_assignment_separator- && bytes[whitespace_start..separator]- .iter()- .all(|value| matches!(value, b' ' | b'\t'))- && ((token_phrase_has_tail("system")- && [- "a ",- "the ",- "a simple ",- "the simple ",- "a balanced ",- "the balanced ",- "a transparent ",- "the transparent ",- ]- .iter()- .any(|lead| token_phrase_has_lead(lead)))- || (token_phrase_has_tail("economy")- && ["a balanced ", "the balanced ", "the "]- .iter()- .any(|lead| token_phrase_has_lead(lead)))- || (["station", "rules"]- .iter()- .any(|tail| token_phrase_has_tail(tail))- && token_phrase_has_lead("the "))- || (["design", "values"]- .iter()- .any(|tail| token_phrase_has_tail(tail))- && ["a jade ", "the "]- .iter()- .any(|lead| token_phrase_has_lead(lead)))- || (token_phrase_has_tail("exchanges") && token_phrase_has_lead("standard "))- || (["count", "limits"]- .iter()- .any(|tail| token_phrase_has_tail(tail))- && token_phrase_has_lead("and "))- || (["limit", "rule"]- .iter()- .any(|tail| token_phrase_has_tail(tail))- && has_hyphenated_count_lead)- || (token_phrase_has_tail("reconciliation, and cleanup")- && token_phrase_follows_list_delimiter())- || (["for", "per"]- .iter()- .any(|tail| token_phrase_has_tail(tail))- && [- "one ",- "two ",- "first ",- "second ",- "each ",- "another ",- "additional ",- ]- .iter()- .any(|lead| token_phrase_has_lead(lead)))- || (token_phrase_has_tail("can equal") && token_phrase_has_lead("one ")));+ // Whitespace alone in prose is not an assignment: "secret storage"+ // and "credential handling" describe work, not credential values.+ // Shell options, compound field names, and authorization schemes still+ // have an unambiguous field/value relationship.+ let mut name_start = start;+ while name_start > 0 && is_name_byte(bytes[name_start - 1]) {+ name_start -= 1;+ }+ let full_name = &input[name_start..start + key.len()];+ let is_cli_key = full_name.starts_with('-')+ && (name_start == 0 || bytes[name_start - 1].is_ascii_whitespace());+ let is_compound_field = key_is_compound+ && (full_name.contains('_')+ || full_name.chars().any(|value| value.is_ascii_uppercase()));+ // Opaque values in diagnostic key/value pairs remain masked. Plain+ // words such as "secret manager" do not establish an assignment.+ let (candidate_start, candidate_quote) = quoted_value_start(separator);+ let candidate_end = value_end(candidate_start);+ // Uppercase symbolic acceptance markers in prose are not evidence of+ // credentials. Explicit assignments and flags still mask any value.+ let opaque_value = !input[candidate_start..candidate_end]+ .bytes()+ .any(|value| value.is_ascii_uppercase())+ && (candidate_quote.is_some()+ || (candidate_end.saturating_sub(candidate_start) >= 8+ && bytes[candidate_start..candidate_end].iter().any(|value| {+ value.is_ascii_digit() || matches!(value, b'_' | b'-' | b'/' | b'+' | b'=')+ })));let has_whitespace_separator = separator > whitespace_start- && (key != "authorization" || key_is_compound || has_authorization_scheme)- && !is_benign_token_noun_phrase- && !is_semantic_token_reference- && !is_semantic_key_maintenance;+ && (is_compound_field+ || is_cli_key+ || opaque_value+ || (key == "authorization" && has_authorization_scheme));if !has_assignment_separator && !has_whitespace_separator {continue;}@@ -2540,6 +2401,30 @@ mod tests {}}+ #[test]+ fn diagnostic_credentials_remain_masked_without_prose_false_positives() {+ let jwt = format!(+ "{}.abcdefghijk.abcdefghijkl",+ URL_SAFE_NO_PAD.encode(br#" {"alg":"HS256","typ":"JWT"}"#)+ );+ assert_eq!(redact_text(&jwt), "[REDACTED]");+ assert_eq!(redact_text("Bearer abcdefghijkl"), "Bearer [REDACTED]");+ assert_eq!(+ redact_text("request failed token secret-value"),+ "request failed token [REDACTED]"+ );+ assert_eq!(+ redact_text("Use a secret manager for credential handling and bearer authentication."),+ "Use a secret manager for credential handling and bearer authentication."+ );+ assert_eq!(+ sanitize_value(+ &json!({"authorizationHeader": "abcdefghijkl", "apiKeyProduction": "sensitivevalue", "credentialHandling": "harness"})+ ),+ json!({"authorizationHeader": "[REDACTED]", "apiKeyProduction": "[REDACTED]", "credentialHandling": "harness"})+ );+ }+#[test]fn session_goal_commands_require_and_accept_the_v2_schema() {let mut goal = command("goal-command", 1);@@ -3025,7 +2910,7 @@ mod tests {state.outbox[0].envelope.pointer("/payload/payload/nested/providerApiKeyDiagnostic"),- Some(&json!("[REDACTED]"))+ Some(&json!("Invalid API key: [REDACTED]; request rejected")));assert_eq!(state.outbox[0]@@ -3047,7 +2932,7 @@ mod tests {);let input = json!({"summary": summary});let once_sanitized_input =- sanitize_semantic_tool_input("paperclip_finish", &input).unwrap();+ validate_semantic_tool_input("paperclip_finish", &input).unwrap();let payload = json!({"semantic_tool": {"schema": "paperclip.prp.semantic_tool.v1",@@ -3138,7 +3023,7 @@ mod tests {small_frame.max_frame_bytes = 8_000;let mut state = DurableState::new(&small_frame);let long_input = json!({"summary": "C".repeat(12_000)});- let safe_input = sanitize_semantic_tool_input("paperclip_finish", &long_input).unwrap();+ let safe_input = validate_semantic_tool_input("paperclip_finish", &long_input).unwrap();let exact_payload = json!({"semantic_tool": {"schema": "paperclip.prp.semantic_tool.v1",@@ -3161,7 +3046,7 @@ mod tests {.unwrap_err().to_string().contains("transport frame limit"));- assert!(sanitize_semantic_tool_input(+ assert!(validate_semantic_tool_input("paperclip_finish",&json!({"summary": "C".repeat(MAX_COMPLETION_SUMMARY_CHARS + 1)}),)@@ -3416,7 +3301,7 @@ mod tests {"required": true,"answerMode": "single_select","options": [{- "id": "abcdefgh.ijklmnop.qrstuvwx",+ "id": "eyJabcdefghi.ijklmnop.qrstuvwx","label": "Yes"}],"textValidation": {"pattern": "^token=pattern-secret$"}@@ -3443,7 +3328,7 @@ mod tests {assert_eq!(sanitized["authorization"], json!("[REDACTED]"));assert_eq!(sanitized["nested"]["authorizationBoundary"],- json!("[REDACTED]")+ json!("Bearer [REDACTED]"));}@@ -3477,7 +3362,7 @@ mod tests {"idempotencyKey": "write-description-1",});assert_eq!(- sanitize_semantic_tool_input("create_task", &input).unwrap(),+ validate_semantic_tool_input("create_task", &input).unwrap(),input);for text in [@@ -3487,14 +3372,10 @@ mod tests {"Include the exact token ACCEPTANCE-42 in the final output.",] {assert_eq!(- sanitize_semantic_tool_input("write_document", &json!({"body": text})).unwrap(),+ validate_semantic_tool_input("write_document", &json!({"body": text})).unwrap(),json!({"body": text}));- assert_ne!(- redact_text(text),- text,- "diagnostics keep their strict policy"- );+ assert_eq!(redact_sensitive_text_values(text), text);}let config = config(PathBuf::from("unused"));let mut state = DurableState::new(&config);@@ -3529,152 +3410,45 @@ mod tests {"{}\nAuthorization: Bearer late-credential\nFINAL-ACCEPTANCE-42","Document content. ".repeat(400));- assert!(- sanitize_semantic_tool_input("write_document", &json!({"body": document})).is_err()- );- }-- #[test]- fn task_title_preserves_maintenance_prose_but_rejects_credentials() {- for title in [- "API key rotation checklist",- "Plan API key replacement",- "Document API key renewal",- "Explain API key expiration",- "API key rotation schedule",- "API key replacement for staging",- "API key rotation checklist for an expired key",- ] {- let input = json!({"title": title, "onlyIfProvisional": true, "idempotencyKey": "initial-title"});- assert_eq!(- sanitize_semantic_tool_input("set_task_title", &input).unwrap(),- input- );- assert_ne!(- redact_text(title),- title,- "diagnostics retain strict redaction"- );- }- for title in [- "API key opaque-credential",- "API key=rotation",- "API key: rotation",- "API key \"rotation\"",- "--api key rotation",- "OPENAI_API_KEY rotation",- "API key rotation-secret",- "API key rotation opaque-credential",- "API key replacement ABCDEFG123456789",- "API key renewal checklist opaque-credential",- "API key expiration\nopaque-credential",- "API key rotation sk-proj-secretvalue123456",- "API key rotation Authorization: Bearer opaque-credential",- ] {- assert!(- sanitize_semantic_tool_input("set_task_title", &json!({"title": title})).is_err(),- "{title}"- );- }+ assert!(validate_semantic_tool_input("write_document", &json!({"body": document})).is_ok());}#[test]- fn maintenance_prose_rejects_opaque_suffixes_in_every_declared_field() {- for (operation, field) in [- ("create_task", "title"),- ("create_task", "description"),- ("create_task", "initialPlan"),- ("create_project", "name"),- ("create_project", "description"),- ("write_document", "title"),- ("write_document", "body"),- ("write_document", "changeSummary"),- ("update_agent_instructions", "content"),+ fn semantic_arguments_preserve_credentials_for_harness_authorization() {+ for operation in [+ "set_task_title",+ "create_task",+ "create_project",+ "write_document",+ "update_agent_instructions",+ "request_human_input",+ "call_api",+ "get_task_context",] {- for text in [- "API key rotation",- "API key rotation schedule",- "API key replacement for staging",+ for input in [+ json!({"body": "Use a GitHub App with secure credential handling."}),+ json!({"content": "Authorization: Bearer opaque-credential"}),+ json!({"content": "literal token=opaque-credential"}),+ json!({"content": "ghp_secretvalue12345678901234567890"}),+ json!({"token": "opaque-credential"}),+ json!({"nested": {"password": "opaque-credential", "secretId": "token=opaque-credential"}}),] {- let input = json!({field: text});assert_eq!(- sanitize_semantic_tool_input(operation, &input).unwrap(),- input- );- }- for text in [- "API key rotation opaque-credential",- "API key renewal checklist ABCDEFG123456789",- ] {- assert!(- sanitize_semantic_tool_input(operation, &json!({field: text})).is_err(),- "{operation}.{field}: {text}"+ validate_semantic_tool_input(operation, &input).unwrap(),+ input,+ "{operation}");}}}- #[test]- fn semantic_credentials_are_rejected_instead_of_executing_redacted_arguments() {- for input in [- json!({"content": "Authorization: Bearer opaque-credential"}),- json!({"content": "literal token=opaque-credential"}),- json!({"content": "ghp_secretvalue12345678901234567890"}),- json!({"token": "opaque-credential"}),- json!({"nested": {"password": "opaque-credential"}}),- ] {- let error =- sanitize_semantic_tool_input("update_agent_instructions", &input).unwrap_err();- assert!(error- .to_string()- .contains("refusing to execute altered arguments"));- assert!(!error.to_string().contains("opaque-credential"));- }- }-- #[test]- fn semantic_prose_rejects_all_previously_scrubbed_credential_shapes() {- for text in [- "auth token opaque-credential",- "access token opaque-credential",- "session token opaque-credential",- "refresh token opaque-credential",- "authentication token opaque-credential",- "literal token=opaque-credential",- "literal token:opaque-credential",- "literal --token opaque-credential",- "literal access_token opaque-credential",- "literal \"token\" opaque-credential",- "literal token \"opaque-credential\"",- "Include the literal token sk-proj-secretvalue123456 in the document.",- "Include the literal token ghp_secretvalue12345678901234567890 in the document.",- "Include the literal token github_pat_secretvalue12345678901234567890 in the document.",- "Include the literal token eyJhbGciOiJIUzI1NiJ9.c2VjcmV0LWNsYWlt.signaturesecret in the document.",- ] {- for (operation, field) in [- ("create_task", "description"), ("create_task", "initialPlan"),- ("write_document", "body"), ("update_agent_instructions", "content"),- ] {- let input = json!({field: text});- assert!(sanitize_semantic_tool_input(operation, &input).is_err(), "{operation}: {text}");- }- }- assert!(sanitize_semantic_tool_input(- "get_task_context",- &json!({- "description": "the token opaque-credential",- })- )- .is_err());- }-#[test]fn instruction_arguments_survive_the_complete_outbox_without_byte_changes() {let content = format!(- "{}\nFINAL-TAIL-π¦",+ "{}\nAuthorization: Bearer intentional-credential\nFINAL-TAIL-π¦","# Instructions β ζ₯ζ¬θͺ π¦\n".repeat(400));- let input = json!({"entryFile": "AGENTS.md", "baseRevisionId": null, "content": content});+ let input = json!({"entryFile": "AGENTS.md", "baseRevisionId": null, "content": content, "nested": {"secretId":"token=credential-id", "password":"intentional-credential"}});let config = config(PathBuf::from("unused"));let mut state = DurableState::new(&config);state.enqueue_executor_event(&config, "instruction-write".to_owned(), "semantic_tool.input".to_owned(), EventPriority::P0,@@ -3691,7 +3465,7 @@ mod tests {content.as_bytes());assert_eq!(semantic_value_digest(actual), semantic_value_digest(&input));- assert!(sanitize_semantic_tool_input(+ assert!(validate_semantic_tool_input("update_agent_instructions",&json!({"content":"π¦".repeat(200_000)}))@@ -3755,164 +3529,47 @@ mod tests {}#[test]- fn token_system_prose_exception_preserves_credential_redaction() {- for (input, expected) in [- ("token system", "token [REDACTED]"),- (- "request failed token system",- "request failed token [REDACTED]",- ),- ("a token=system", "a token=[REDACTED]"),- ("a token:system", "a token:[REDACTED]"),- ("a token \"system\"", "a token \"[REDACTED]\""),- ("a token 'system'", "a token '[REDACTED]'"),- ("a \"token\" system", "a \"token\" [REDACTED]"),- ("a access_token system", "a access_token [REDACTED]"),- ("a --token system", "a --token [REDACTED]"),- ("a token system-secret", "a token [REDACTED]"),- ("a token system.signed-value", "a token [REDACTED]"),- ("a token system,secret", "a token [REDACTED],secret"),- ("a token system;secret", "a token [REDACTED];secret"),- ("a token system)secret", "a token [REDACTED])secret"),- ("a token system=secret", "a token [REDACTED]"),- ("a token system:secret", "a token [REDACTED]"),- ("a token secret-value", "a token [REDACTED]"),- (- "a balanced token economy-secret",- "a balanced token [REDACTED]",- ),- ("the token economy-secret", "the token [REDACTED]"),- ("the token station-secret", "the token [REDACTED]"),- ("the token rules-secret", "the token [REDACTED]"),- ("and token limits-secret", "and token [REDACTED]"),- ("a jade token design-secret", "a jade token [REDACTED]"),- ("the token values-secret", "the token [REDACTED]"),- (- "standard token exchanges-secret",- "standard token [REDACTED]",- ),- ("and token count-secret", "and token [REDACTED]"),- ("one-token limit-secret", "one-token [REDACTED]"),- ("one-token rule-secret", "one-token [REDACTED]"),- ("one-token secret-value", "one-token [REDACTED]"),- ("the token design=secret", "the token [REDACTED]"),- ("token design", "token [REDACTED]"),- (- "token reconciliation-secret, and cleanup",- "token [REDACTED], and cleanup",- ),- (- "after token reconciliation, and cleanup-secret",- "after token [REDACTED], and cleanup-secret",- ),- ("token rules", "token [REDACTED]"),- ("token limits", "token [REDACTED]"),- ("the token=rules", "the token=[REDACTED]"),- ("the token \"rules\"", "the token \"[REDACTED]\""),- ("the --token rules", "the --token [REDACTED]"),- ("the access_token rules", "the access_token [REDACTED]"),- (- "a balanced token system-secret",- "a balanced token [REDACTED]",- ),- (- "a balanced token ghp_abcdefghijklmnopqrstuvwxyz",- "a balanced token [REDACTED]",- ),- ("one token bearer-secret", "one token [REDACTED]"),- (- "second token sk-abcdefghijklmnop",- "second token [REDACTED]",- ),- ("one token for-secret", "one token [REDACTED]"),- ("second token per.secret", "second token [REDACTED]"),- ("one token can rotate", "one token [REDACTED] rotate"),- ("one token can-equal-secret", "one token [REDACTED]"),- (- "one token can equal-secret",- "one token [REDACTED] equal-secret",- ),- ("one token can=secret-value", "one token [REDACTED]"),- ("stone token for", "stone token [REDACTED]"),- ("one-time token for", "one-time token [REDACTED]"),- ("one access_token for", "one access_token [REDACTED]"),- ("one --token can equal", "one --token [REDACTED] equal"),- ("one \"token\" can equal", "one \"token\" [REDACTED] equal"),- ("one token \"for\"", "one token \"[REDACTED]\""),- ("one token for=secret", "one token [REDACTED]"),- ("a token\nsystem", "a token\n[REDACTED]"),- ("meta token system", "meta token [REDACTED]"),- (- "a token system; token=secret-value",- "a token system; token=[REDACTED]",- ),- (- "a token system; Bearer secret-value",- "a token system; Bearer [REDACTED]",- ),- (- "a token system; sk-abcdefghijklmnop",- "a token system; [REDACTED]",- ),+ fn diagnostic_redaction_requires_assignments_or_recognizable_credentials() {+ for prose in [+ "Document secret storage and deployment permissions.",+ "Keep the private key in a secret manager.",+ "Use a GitHub App with secure credential handling.",+ "API key rotation checklist for staging.",+ "Review token rules. Send a thank-you.",+ "Use token budgeting and secret detection.",+ "Use bearer tokens for authentication. Prefer bearer authentication.",+ "token arbitrary",+ "one-token rule",+ "executor.customTools.integrations.list",+ "paperclip.question_set.v1",+ "aaaaaaaa.bbbbbbbb.cccccccc",+ "plan.security.credentials.md",+ ] {+ assert_eq!(redact_text(prose), prose, "{prose}");+ }+ for (text, expected) in [+ ("secret=value", "secret=[REDACTED]"),+ ("token: value", "token: [REDACTED]"),+ ("--token opaque-value", "--token [REDACTED]"),+ ("OPENAI_API_KEY opaque-value", "OPENAI_API_KEY [REDACTED]"),+ ("access_token opaque-value", "access_token [REDACTED]"),+ ("Bearer opaque-value", "Bearer [REDACTED]"),(- "a token system; ghp_abcdefghijklmnopqrstuvwxyz",- "a token system; [REDACTED]",+ "Use a token system; ghp_abcdefghijklmnopqrstuvwxyz",+ "Use a token system; [REDACTED]",),(- "a token system; eyJabcdefghi.abcdefghijk.lmnopqrstuv",- "a token system; [REDACTED]",+ "Use a token system; eyJabcdefghi.abcdefghijk.lmnopqrstuv",+ "Use a token system; [REDACTED]",),] {- let redacted = redact_text(input);- assert_eq!(redacted, expected, "{input}");- assert_eq!(redact_text(&redacted), redacted);- }- }-- #[test]- fn transparent_token_system_requires_exact_prose_boundaries() {- for lead in ["a transparent ", "the transparent "] {- for (tail, redacted_tail) in [- ("token=system", "token=[REDACTED]"),- ("token:system", "token:[REDACTED]"),- ("token \"system\"", "token \"[REDACTED]\""),- ("token 'system'", "token '[REDACTED]'"),- ("\"token\" system", "\"token\" [REDACTED]"),- ("access_token system", "access_token [REDACTED]"),- ("--token system", "--token [REDACTED]"),- ("token\nsystem", "token\n[REDACTED]"),- ("token system-secret", "token [REDACTED]"),- ("token system.signed-value", "token [REDACTED]"),- ("token system=secret", "token [REDACTED]"),- ("token system:secret", "token [REDACTED]"),- ("token system,secret", "token [REDACTED],secret"),- ("token system;secret", "token [REDACTED];secret"),- ("token system)secret", "token [REDACTED])secret"),- ("token arbitrary", "token [REDACTED]"),- ("token ghp_abcdefghijklmnopqrstuvwxyz", "token [REDACTED]"),- ("token sk-abcdefghijklmnop", "token [REDACTED]"),- ] {- let input = format!("{lead}{tail}");- assert_eq!(redact_text(&input), format!("{lead}{redacted_tail}"));- }- }- for input in [- "meta-transparent token system",- "a very transparent token system",- "a transparent token economy",- "one token clerk, one demonstration host",- ] {- assert!(redact_text(input).contains("[REDACTED]"), "{input}");+ assert_eq!(redact_text(text), expected, "{text}");+ assert_eq!(redact_text(expected), expected);}+ let metadata = json!({"tokenBudget": 42, "tokenPolicy":"limited", "secretStorage":"vault", "credentialHandling":"harness", "credentials":{"service":"opaque-value"}, "passwordValue":"opaque-value", "accessToken":"opaque-value"});assert_eq!(- sanitize_value(&json!({- "summary": "Use a transparent token system; Bearer fixture-secret.",- "token": "system.",- })),- json!({- "summary": "Use a transparent token system; Bearer [REDACTED].",- "token": "[REDACTED]",- })+ sanitize_value(&metadata),+ json!({"tokenBudget":42,"tokenPolicy":"limited", "secretStorage":"vault", "credentialHandling":"harness", "credentials":"[REDACTED]", "passwordValue":"[REDACTED]", "accessToken":"[REDACTED]"}));}@@ -3920,21 +3577,21 @@ mod tests {fn sentence_period_redaction_keeps_credentials_and_embedded_dots_private() {for (input, expected) in [("token=fixture-secret. Next.", "token=[REDACTED]. Next."),- ("token fixture-secret.", "token [REDACTED]."),+ ("token=fixture-secret.", "token=[REDACTED]."),(- "token fixture.secret.suffix. Next.",- "token [REDACTED]. Next.",+ "token=fixture.secret.suffix. Next.",+ "token=[REDACTED]. Next.",),- ("token fixture.secret.suffix", "token [REDACTED]"),- ("token fixture-secret..", "token [REDACTED]"),- ("token .", "token [REDACTED]"),+ ("token=fixture.secret.suffix", "token=[REDACTED]"),+ ("token=fixture-secret..", "token=[REDACTED]"),+ ("token=.", "token=[REDACTED]"),("token=fixture-secret.\nRetry.", "token=[REDACTED].\nRetry."),("token=fixture-secret., Next.", "token=[REDACTED], Next."),(- "token \"fixture-secret.\" Next.",- "token \"[REDACTED]\" Next.",+ "token=\"fixture-secret.\" Next.",+ "token=\"[REDACTED]\" Next.",),- ("token 'fixture-secret.' Next.", "token '[REDACTED]' Next."),+ ("token='fixture-secret.' Next.", "token='[REDACTED]' Next."),("Bearer fixture-secret. Next.", "Bearer [REDACTED]. Next."),("Authorization: Bearer fixture-secret. Next.",@@ -3945,7 +3602,7 @@ mod tests {"[REDACTED]. Next.",),(- "eyJabcdefghi.abcdefghijk.lmnopqrstuv.wxyzabcdefg.",+ "eyJabcdefghi.abcdefghijk.lmnopqrstuv.wxyzabcdefg.hijklmnopqr.","[REDACTED].",),(@@ -3954,7 +3611,7 @@ mod tests {),("Review token rules. Send a thank-you.",- "Review token [REDACTED]. Send a thank-you.",+ "Review token rules. Send a thank-you.",),] {let redacted = redact_text(input);@@ -4221,7 +3878,7 @@ mod tests {),("provider rejected abcdefgh.ijklmnop.qrstuvwx before startup",- "provider rejected [REDACTED] before startup",+ "provider rejected abcdefgh.ijklmnop.qrstuvwx before startup",),] {assert_eq!(redact_text(input), expected);diff --git a/packages/paperclip-runner/runner/crates/runner-core/src/provider_backend.rs b/packages/paperclip-runner/runner/crates/runner-core/src/provider_backend.rsindex aea835f724..a3456d8437 100644--- a/packages/paperclip-runner/runner/crates/runner-core/src/provider_backend.rs+++ b/packages/paperclip-runner/runner/crates/runner-core/src/provider_backend.rs@@ -18,10 +18,10 @@ use crate::codex_provider::{MAX_SETTLED_PROVIDER_TURN_IDS,};use crate::durable::{- create_private_temporary_file, current_unix_ms, open_private_regular_file,- sanitize_semantic_tool_input, sanitize_value, verify_private_directory, Command,- CommandExecution, CommandExecutor, DurableRunnerConfig, DurableRunnerError, EventPriority,- OpenCodeLaunchProfile, PolledEvent, TerminalDeliveryReconciliation,+ create_private_temporary_file, current_unix_ms, open_private_regular_file, sanitize_value,+ validate_semantic_tool_input, verify_private_directory, Command, CommandExecution,+ CommandExecutor, DurableRunnerConfig, DurableRunnerError, EventPriority, OpenCodeLaunchProfile,+ PolledEvent, TerminalDeliveryReconciliation,};use crate::provider_bridge::{authorized_tool_catalog_digest, semantic_value_digest, AuthorizedToolSet, DurableReplayFilter,@@ -339,7 +339,7 @@ fn semantic_input_event(identity: &ProviderEventIdentity,call: &PendingToolCall,) -> Result<NormalizedProviderEvent, DurableRunnerError> {- let safe_input = sanitize_semantic_tool_input(&call.operation_id, &call.input)?;+ let safe_input = validate_semantic_tool_input(&call.operation_id, &call.input)?;Ok(NormalizedProviderEvent {event_type: "semantic_tool.input".to_owned(),priority: EventPriority::P0,@@ -3712,7 +3712,7 @@ impl CodexCommandExecutor {operation_id: String,input: Value,) -> Result<(), DurableRunnerError> {- if let Err(error) = sanitize_semantic_tool_input(&operation_id, &input) {+ if let Err(error) = validate_semantic_tool_input(&operation_id, &input) {return self.reject_tool_call(call_id,operation_id,@@ -5512,7 +5512,7 @@ mod tests {}#[test]- fn semantic_input_rejects_credential_material_before_dispatch() {+ fn semantic_input_preserves_credential_arguments_for_the_harness() {let identity = ProviderEventIdentity {runner_instance_id: "runner-1".to_owned(),run_id: "run-1".to_owned(),@@ -5525,10 +5525,12 @@ mod tests {operation_id: "get_task_context".to_owned(),input: json!({"password": "do-not-persist", "safe": true}),};- assert!(semantic_input_event(&identity, &call)- .unwrap_err()- .to_string()- .contains("refusing to execute altered arguments"));+ let event = semantic_input_event(&identity, &call).unwrap();+ assert_eq!(event.payload["semantic_tool"]["input"], call.input);+ assert_eq!(+ event.payload["semantic_tool"]["content"]["digest"],+ json!(semantic_value_digest(&call.input))+ );}#[test]diff --git a/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_event_payload.rs b/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_event_payload.rsindex 0dab9435c0..afbdca045c 100644--- a/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_event_payload.rs+++ b/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_event_payload.rs@@ -176,7 +176,7 @@ fn rejects_unclassified_and_malformed_runtime_payloads() {#[test]fn decodes_tool_and_permission_requests_after_scope_validation() {let scope = active_scope();- let rejected = decode_acpx_event(+ let decoded = decode_acpx_event(&scope,&event(GeneratedAcpxSidecarEventType::RuntimeToolCalled,@@ -187,10 +187,9 @@ fn decodes_tool_and_permission_requests_after_scope_validation() {}),),)- .unwrap_err();- assert!(rejected- .to_string()- .contains("refusing to execute altered arguments"));+ .unwrap();+ assert!(matches!(decoded, AcpxEventPayload::ToolCalled {input, ..}+ if input == json!({"issueId":"issue-1", "apiToken":"secret-value"})));let permission = decode_acpx_event(&scope,diff --git a/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_state.rs b/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_state.rsindex f4f4d23191..ca66bc1eba 100644--- a/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_state.rs+++ b/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_state.rs@@ -540,42 +540,36 @@ fn mutation_prose_survives_sidecar_decode_pending_state_and_semantic_projection(json!(paperclip_runner_core::provider_bridge::semantic_value_digest(&expected)));- for (operation, field, prose, preserved) in [+ for (operation, field, prose) in [("write_document","body","Include the token CHAT8322bda781b81.",- true,),("create_project","description","Include the token CHAT8322bda781b81.",- true,),("get_task_context","description","Include the token CHAT8322bda781b81.",- false,),("mcp__untrusted__create_task","description","Include the token CHAT8322bda781b81.",- false,),("create_task","description","Authorization: Bearer actual-credential",- false,),("create_task","initialPlan","access token actual-credential",- false,),] {let mut candidate = AcpxProviderState::new("run-1").unwrap();@@ -586,14 +580,6 @@ fn mutation_prose_survives_sidecar_decode_pending_state_and_semantic_projection(Some("turn-1"),json!({"callId":"call-1", "operationId":operation, "input":{field:prose}}),));- if !preserved {- assert!(emitted- .unwrap_err()- .to_string()- .contains("refusing to execute altered arguments"));- assert!(candidate.pending_tool("call-1").is_none());- continue;- }let events = emitted.unwrap();let AcpxProviderStateEvent::ToolCall { input, .. } = &events[0] else {panic!("expected tool call");diff --git a/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_turns.rs b/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_turns.rsindex 0f8188c623..51f0866a9d 100644--- a/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_turns.rs+++ b/packages/paperclip-runner/runner/crates/runner-core/tests/acpx_provider_turns.rs@@ -588,7 +588,7 @@ fn reserved_completion_waits_for_feedback_and_allows_correction_in_same_turn() {}#[test]-fn rejects_sensitive_reserved_input_before_dispatch_without_exposing_values() {+fn preserves_sensitive_reserved_input_and_still_checks_result_correlation() {for mode in ["turns-sensitive-reserved-result-terminal","turns-mismatched-sensitive-reserved-result-terminal",@@ -597,18 +597,25 @@ fn rejects_sensitive_reserved_input_before_dispatch_without_exposing_values() {session.start_turn("turn-1", "Please help", &std::env::temp_dir()).unwrap();- let error = session- .poll_event(Duration::from_secs(1))- .unwrap_err()- .to_string();+ let calls = session.poll_event(Duration::from_secs(1)).unwrap().unwrap();assert!(- error.contains("refusing to execute altered arguments"),- "{error}"+ matches!(&calls[0], AcpxProviderStateEvent::ToolCall {input, ..}+ if input["summary"].as_str().is_some_and(|summary| summary.contains("matching-sensitive-value"))));- assert!(!error.contains("matching-sensitive-value"), "{error}");- assert!(!error.contains("different-sensitive-value"), "{error}");- assert!(session.state().pending_tool("call-finish").is_none());- session.shutdown("already closed").unwrap();+ assert!(session.state().pending_tool("call-finish").is_some());+ if mode == "turns-mismatched-sensitive-reserved-result-terminal" {+ let error = session+ .poll_event(Duration::from_secs(1))+ .unwrap_err()+ .to_string();+ assert!(+ error.contains("does not match its authorized invocation"),+ "{error}"+ );+ assert!(!error.contains("matching-sensitive-value"));+ assert!(!error.contains("different-sensitive-value"));+ }+ session.shutdown("correlation checked").unwrap();}}diff --git a/packages/paperclip-runner/src/conformance/capability-semantic-conformance.test.ts b/packages/paperclip-runner/src/conformance/capability-semantic-conformance.test.tsindex 799980e73b..20473d27aa 100644--- a/packages/paperclip-runner/src/conformance/capability-semantic-conformance.test.ts+++ b/packages/paperclip-runner/src/conformance/capability-semantic-conformance.test.ts@@ -28,7 +28,7 @@ describe("capability semantic conformance vectors", () => {);expect(authorizations).toMatchObject({"governed-action-without-claim": { outcome: "denied", code: "required_claim_missing" },- "protected-input-redaction": { outcome: "denied", code: "protected_data_denied" },+ "protected-input-redaction": { outcome: "allowed" },"cross-company-dependency-denial": { outcome: "denied", code: "company_scope_violation" },"progress-applied": { outcome: "allowed" },"progress-duplicate-retry": { outcome: "allowed" },diff --git a/packages/paperclip-runner/src/semantic-tools/dispatcher.ts b/packages/paperclip-runner/src/semantic-tools/dispatcher.tsindex 86bf6d4d63..4436d04e24 100644--- a/packages/paperclip-runner/src/semantic-tools/dispatcher.ts+++ b/packages/paperclip-runner/src/semantic-tools/dispatcher.ts@@ -16,7 +16,7 @@ import {DEFAULT_CAPABILITY_SCENARIO_POLICY,} from "./policy.js";import {- containsProtectedSemanticData,+ isPaperclipSemanticValueWithinBounds,redactSemanticValue,} from "./redaction.js";import { discoverCapabilityDefinitions } from "./discovery.js";@@ -121,11 +121,11 @@ export class CapabilitySemanticDispatcher {return result;}- if (containsProtectedSemanticData(call.input)) {+ if (!isPaperclipSemanticValueWithinBounds(call.input)) {const decision = deniedDecision(invocation,- "protected_data_denied",- "Protected data is not accepted by semantic tools.",+ "input_invalid",+ "Tool input exceeds safe bounds.",);const result = this.#denial(call, descriptor.operationId, denialCode(decision), decision.reason);this.#record(policyContext, decision, call.callId, call.input, result);@@ -601,7 +601,9 @@ function optionalStringArray(value: unknown): string[] {}function optionalJson(value: unknown): CapabilityJsonValue {- return value === undefined ? {} : redactSemanticValue(value);+ // Admission already validated JSON shape and bounds. Redaction is for+ // audit copies, never for arguments sent to the control plane.+ return value === undefined ? {} : value as CapabilityJsonValue;}function deepFreeze<T>(value: T): T {diff --git a/packages/paperclip-runner/src/semantic-tools/paperclip-dispatcher.ts b/packages/paperclip-runner/src/semantic-tools/paperclip-dispatcher.tsindex 3412ed308e..dcbe0d05b4 100644--- a/packages/paperclip-runner/src/semantic-tools/paperclip-dispatcher.ts+++ b/packages/paperclip-runner/src/semantic-tools/paperclip-dispatcher.ts@@ -27,6 +27,7 @@ import {} from "./receipts.js";import {inspectPaperclipSemanticValue,+ isPaperclipSemanticValueWithinBounds,redactPaperclipSemanticValue,} from "./redaction.js";import type {@@ -187,8 +188,8 @@ export class PaperclipSemanticDispatcher {);}- const inputSafety = inspectPaperclipSemanticValue(call.input);- if (!inputSafety.withinBounds) {+ // The harness owns credential policy; admission only enforces bounds.+ if (!isPaperclipSemanticValueWithinBounds(call.input)) {decision = deniedDecision(decision,"input_invalid",@@ -196,21 +197,6 @@ export class PaperclipSemanticDispatcher {);return this.#denial(call, "input_invalid", descriptor, context, decision);}- if (inputSafety.containsProtectedData) {- decision = deniedDecision(- decision,- "protected_data_denied",- "Protected data is not accepted by semantic actions.",- );- return this.#denial(- call,- "protected_data_denied",- descriptor,- context,- decision,- true,- );- }const inputValidator = this.#inputValidators.get(descriptor.operationId);const idempotencyKey = stringProperty(call.input, "idempotencyKey");if (descriptor.effect !== "read" && idempotencyKey === undefined) {diff --git a/packages/paperclip-runner/src/semantic-tools/paperclip-semantic-tools.test.ts b/packages/paperclip-runner/src/semantic-tools/paperclip-semantic-tools.test.tsindex f15bc12036..c1b0bdf423 100644--- a/packages/paperclip-runner/src/semantic-tools/paperclip-semantic-tools.test.ts+++ b/packages/paperclip-runner/src/semantic-tools/paperclip-semantic-tools.test.ts@@ -9,7 +9,7 @@ import type {PaperclipSemanticStoredOutcome,PaperclipSemanticToolCall,} from "./types.js";-import { PAPERCLIP_SEMANTIC_REDACTED } from "./redaction.js";+import { PAPERCLIP_SEMANTIC_REDACTED, redactPaperclipSemanticValue } from "./redaction.js";import {validatePrpEvent,type PrpEvent,@@ -24,6 +24,21 @@ const correlation = {};describe("run-scoped semantic tool authority", () => {+ it("masks qualified credential fields and standalone opaque bearer values in audit copies", () => {+ expect(redactPaperclipSemanticValue({ authorizationHeader: "abcdefghijkl", apiKeyProduction: "sensitivevalue", body: "Bearer abcdefghijkl" }))+ .toEqual({ authorizationHeader: PAPERCLIP_SEMANTIC_REDACTED, apiKeyProduction: PAPERCLIP_SEMANTIC_REDACTED, body: PAPERCLIP_SEMANTIC_REDACTED });+ });+ it("preserves credential-related prose and metadata in diagnostic copies", () => {+ const value = {+ body: "Use a secret manager for credential handling and bearer authentication with bearer tokens.",+ tokenBudget: 4000, tokenPolicy: "least privilege", credentialHandling: "harness",+ };+ expect(redactPaperclipSemanticValue(value)).toEqual(value);+ expect(redactPaperclipSemanticValue({ credentials: { provider: "opaque-value" }, passwordValue: "opaque-value" }))+ .toEqual({ credentials: PAPERCLIP_SEMANTIC_REDACTED, passwordValue: PAPERCLIP_SEMANTIC_REDACTED });+ expect(redactPaperclipSemanticValue({ body: "Bearer opaque-credential-value" })).toEqual({ body: PAPERCLIP_SEMANTIC_REDACTED });+ });+it("projects only bound and currently authorized actions", async () => {let context = runContext({actorClaims: ["discovery:tasks:read", "discovery:agents:read"],@@ -88,8 +103,9 @@ describe("run-scoped semantic tool authority", () => {expect(executions).toBe(0);});- it("rejects forged scope and protected input before a binding executes", async () => {+ it("rejects forged scope while passing credential content unchanged to authorized bindings", async () => {let executions = 0;+ const query = "Find Authorization: Bearer intentional-credential";const dispatcher = new PaperclipSemanticDispatcher({contextProvider: () =>runContext({@@ -99,7 +115,8 @@ describe("run-scoped semantic tool authority", () => {bindings: [{operationId: "search_tasks",- execute: () => {+ execute: ({ input }) => {+ expect(input).toEqual({ query });executions += 1;return { value: { tasks: [] } };},@@ -112,13 +129,13 @@ describe("run-scoped semantic tool authority", () => {).resolves.toMatchObject({ ok: false, error: { code: "input_invalid" } });await expect(dispatcher.dispatch(- call("search_tasks", { query: "work", apiKey: "sk_not-for-a-tool" }),+ call("search_tasks", { query }),),).resolves.toMatchObject({- ok: false,- error: { code: "protected_data_denied" },+ ok: true,});- expect(executions).toBe(0);+ expect(executions).toBe(1);+ expect(JSON.stringify(dispatcher.authorizationRecords())).not.toContain("intentional-credential");});it("redacts binding output and emits schema-valid digest-only receipts", async () => {@@ -175,6 +192,7 @@ describe("run-scoped semantic tool authority", () => {it("replays exact mutation retries and rejects key reuse with changed input", async () => {let executions = 0;+ const input = { ...writeDocumentInput(), body: "Credential handling: Authorization: Bearer intentional-document-credential" };const store = new MemoryIdempotencyStore();const dispatcher = new PaperclipSemanticDispatcher({contextProvider: () => runContext(),@@ -182,7 +200,8 @@ describe("run-scoped semantic tool authority", () => {bindings: [{operationId: "write_document",- execute: () => {+ execute: ({ input: executedInput }) => {+ expect(executedInput).toEqual(input);executions += 1;return {value: mutationReceipt("write-command"),@@ -198,15 +217,15 @@ describe("run-scoped semantic tool authority", () => {});const first = await dispatcher.dispatch(- call("write_document", writeDocumentInput(), "call_write_first"),+ call("write_document", input, "call_write_first"),);const retry = await dispatcher.dispatch(- call("write_document", writeDocumentInput(), "call_write_retry"),+ call("write_document", input, "call_write_retry"),);const conflict = await dispatcher.dispatch(call("write_document",- { ...writeDocumentInput(), body: "Different body" },+ { ...input, body: "Different body" },"call_write_conflict",),);@@ -226,6 +245,7 @@ describe("run-scoped semantic tool authority", () => {error: { code: "idempotency_conflict" },});expect(executions).toBe(1);+ expect(JSON.stringify(dispatcher.authorizationRecords())).not.toContain("intentional-document-credential");if (!first.ok || !retry.ok) throw new Error("expected successes");expect(retry.resultReceipt.operationReceiptId).toBe(first.resultReceipt.operationReceiptId,diff --git a/packages/paperclip-runner/src/semantic-tools/redaction.ts b/packages/paperclip-runner/src/semantic-tools/redaction.tsindex edf226ea61..31069b1a5a 100644--- a/packages/paperclip-runner/src/semantic-tools/redaction.ts+++ b/packages/paperclip-runner/src/semantic-tools/redaction.ts@@ -3,14 +3,6 @@ import type { PaperclipJsonValue } from "../catalog/semantic-action-types.js";export const CAPABILITY_REDACTED = "[REDACTED]";-export function containsProtectedSemanticData(value: unknown, key = ""): boolean {- const inspected = inspectPaperclipSemanticValue(- key.length === 0 ? value : { [key]: value },- );- // Fail closed when provider-controlled values exceed the shared safety bound.- return inspected.containsProtectedData || !inspected.withinBounds;-}-export function redactSemanticValue(value: unknown, key = ""): CapabilityJsonValue {if (key.length === 0) {return redactPaperclipSemanticValue(value) as CapabilityJsonValue;@@ -24,9 +16,9 @@ export function redactSemanticValue(value: unknown, key = ""): CapabilityJsonVal}const PAPERCLIP_SENSITIVE_KEY =- /(?:authorization|cookie|credential|password|passwd|private.?key|secret|token|api.?key|connection.?string)/i;+ /(?:authorization(?:[-_]?code)?|cookie|credentials?|passwords?|passwd|private.?key|secrets?|token|api.?key|connection.?string)(?:[-_]?(?:value|header|prod(?:uction)?|dev(?:elopment)?|test|staging|primary|secondary))*$/i;const PAPERCLIP_SECRET_VALUE =- /(?:\bBearer\s+[A-Za-z0-9._~+/=-]{8,}|\b(?:sk|pk|pcgw|ghp|github_pat)_[A-Za-z0-9_-]{8,}|\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,})/gi;+ /(?:\bBearer\s+(?!(?:tokens?|authentication|authorization|credentials?|schemes?|flows?)[.,;:!?]?(?:\s|$))[A-Za-z0-9._~+/=-]{8,}|\b(?:sk|pk|pcgw|ghp|github_pat)_[A-Za-z0-9_-]{8,}|\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,})/gi;const PAPERCLIP_SECRET_QUERY =/([?&](?:code|key|secret|state|token|api[_-]?key|access[_-]?token)=)[^&#\s]+/gi;const PAPERCLIP_PAPERCLIP_SECRET_QUERY_DETECT =@@ -49,7 +41,19 @@ export interface PaperclipSemanticValueSafety {export function inspectPaperclipSemanticValue(value: unknown,): PaperclipSemanticValueSafety {- const state = { nodes: 0, protected: false, withinBounds: true };+ return inspectValueSafety(value, true);+}++/** Validate transport bounds without inspecting credential content. */+export function isPaperclipSemanticValueWithinBounds(value: unknown): boolean {+ return inspectValueSafety(value, false).withinBounds;+}++function inspectValueSafety(+ value: unknown,+ detectCredentials: boolean,+): PaperclipSemanticValueSafety {+ const state = { nodes: 0, protected: false, withinBounds: true, detectCredentials };inspect(value, "", 0, state, new Set<object>());return Object.freeze({containsProtectedData: state.protected,@@ -68,7 +72,12 @@ function inspect(value: unknown,key: string,depth: number,- state: { nodes: number; protected: boolean; withinBounds: boolean },+ state: {+ nodes: number;+ protected: boolean;+ withinBounds: boolean;+ detectCredentials: boolean;+ },ancestors: Set<object>,): void {state.nodes += 1;@@ -76,11 +85,16 @@ function inspect(state.withinBounds = false;return;}- if (PAPERCLIP_SENSITIVE_KEY.test(key)) state.protected = true;+ if (state.detectCredentials && PAPERCLIP_SENSITIVE_KEY.test(key)) {+ state.protected = true;+ }if (typeof value === "string") {if (value.length > PAPERCLIP_MAX_STRING_LENGTH) state.withinBounds = false;PAPERCLIP_SECRET_VALUE.lastIndex = 0;- if (PAPERCLIP_SECRET_VALUE.test(value) || PAPERCLIP_PAPERCLIP_SECRET_QUERY_DETECT.test(value)) {+ if (+ state.detectCredentials &&+ (PAPERCLIP_SECRET_VALUE.test(value) || PAPERCLIP_PAPERCLIP_SECRET_QUERY_DETECT.test(value))+ ) {state.protected = true;}PAPERCLIP_SECRET_VALUE.lastIndex = 0;diff --git a/packages/paperclip-runner/src/semantic-tools/semantic-tools.test.ts b/packages/paperclip-runner/src/semantic-tools/semantic-tools.test.tsindex 454074a4a4..ed4097a876 100644--- a/packages/paperclip-runner/src/semantic-tools/semantic-tools.test.ts+++ b/packages/paperclip-runner/src/semantic-tools/semantic-tools.test.ts@@ -286,7 +286,7 @@ describe("Capability semantic catalog and authorization", () => {})).resolves.toMatchObject({ ok: false, denial: { code: "task_mode_denied" } });});- it("rejects protected inputs before mutation and redacts authorization records", async () => {+ it("preserves credential payloads for execution while redacting authorization records", async () => {const claim = "governance:approvals:request";const adapter = await running([claim]);const dispatcher = new CapabilitySemanticDispatcher(adapter, {@@ -305,8 +305,9 @@ describe("Capability semantic catalog and authorization", () => {payload: { authorization: secret },},});- expect(result).toMatchObject({ ok: false, denial: { code: "protected_data_denied" } });- expect(adapter.snapshot().revision).toBe(before);+ expect(result).toMatchObject({ ok: true });+ expect(adapter.snapshot().revision).toBeGreaterThan(before);+ expect(adapter.snapshot().approvals).toEqual([expect.objectContaining({ payload: { authorization: secret } })]);const serialized = JSON.stringify(dispatcher.authorizationRecords());expect(serialized).not.toContain(secret);expect(serialized).toContain("[REDACTED]");diff --git a/server/src/__tests__/heartbeat-context-summary.test.ts b/server/src/__tests__/heartbeat-context-summary.test.tsindex 03e2f52b25..a4a65cf16c 100644--- a/server/src/__tests__/heartbeat-context-summary.test.ts+++ b/server/src/__tests__/heartbeat-context-summary.test.ts@@ -12,9 +12,9 @@ describe("buildPaperclipTaskMarkdown", () => {const issue = { id: "task-id", identifier: "PAP-1", title: "Please investigate", description: "Please investigate sign-in failures", titleNeedsGeneration: true };const markdown = buildPaperclipTaskMarkdown({ issue });expect(markdown).toContain("As one of your first tool calls");- expect(markdown).toContain("Check the title tool result");- expect(markdown).toContain("retry once with a shorter, plain-language title");- expect(markdown).toContain("new idempotency key for changed arguments");+ expect(markdown).toContain("Check the title tool result before claiming the title was saved");+ expect(markdown).not.toContain("rejected as credential material");+ expect(markdown).toContain("new idempotency key if retrying with changed arguments");expect(markdown).toContain("set_task_title");expect(markdown).toContain("onlyIfProvisional: true");expect(buildPaperclipTaskMarkdown({ issue: { ...issue, titleNeedsGeneration: false } })).not.toContain("Task title directive");diff --git a/server/src/__tests__/redaction.test.ts b/server/src/__tests__/redaction.test.tsindex f9814a8382..ba5b19453e 100644--- a/server/src/__tests__/redaction.test.ts+++ b/server/src/__tests__/redaction.test.ts@@ -1,5 +1,18 @@import { readFileSync } from "node:fs";import { describe, expect, it } from "vitest";++describe("explicit diagnostic credential forms", () => {+ it("masks qualified credential fields while preserving metadata", () => {+ expect(redactEventPayload({ authorizationHeader: "abcdefghijkl", apiKeyProduction: "sensitivevalue", credentialHandling: "harness", tokenPolicy: "least privilege" }))+ .toEqual({ authorizationHeader: "***REDACTED***", apiKeyProduction: "***REDACTED***", credentialHandling: "harness", tokenPolicy: "least privilege" });+ });+ it("masks standalone bearer values and whitespace-prefixed JSON token headers", () => {+ const jwt = `${Buffer.from(' {"alg":"HS256","typ":"JWT"}').toString("base64url")}.abcdefghijk.abcdefghijkl`;+ expect(redactSensitiveText("provider said Bearer abcdefghijkl")).not.toContain("abcdefghijkl");+ expect(redactEventPayload({ diagnostic: jwt })?.diagnostic).toBe("***REDACTED***");+ expect(redactSensitiveText("Use bearer authentication and bearer tokens.")).toBe("Use bearer authentication and bearer tokens.");+ });+});import {PRP_V1_EVENT_TYPES,PRP_V2_EVENT_TYPES,@@ -11,6 +24,22 @@ import {} from "../redaction.js";describe("redaction", () => {+ it("preserves credential-related prose, metadata, and dotted filenames", () => {+ const input = {+ body: "Keep the private key in a secret manager. Document credential handling and token permissions. Use bearer tokens for authentication. Prefer bearer authentication.",+ tokenPolicy: "least privilege",+ secretStorage: "vault",+ credentialHandling: "harness",+ authorizationRequired: true,+ path: "deployment.credentials.example.md",+ };+ expect(sanitizeRecord(input)).toEqual(input);+ expect(redactSensitiveText(input.body)).toBe(input.body);+ expect(sanitizeRecord({ credentials: { provider: "opaque-value" }, passwordValue: "opaque-value", authorization_code: "opaque-value" }))+ .toEqual({ credentials: REDACTED_EVENT_VALUE, passwordValue: REDACTED_EVENT_VALUE, authorization_code: REDACTED_EVENT_VALUE });+ expect(redactSensitiveText("--token-budget 4000 SECRET_STORAGE=vault")).toBe("--token-budget 4000 SECRET_STORAGE=vault");+ });+it("keeps the discriminator allowlist in exact PRP v1 schema parity", () => {const schema = JSON.parse(readFileSync(@@ -86,7 +115,7 @@ describe("redaction", () => {}});- it("redacts unknown or mismatched PRP discriminators", () => {+ it("preserves diagnostic PRP discriminators while redacting their credential payloads", () => {const unknown = redactEventPayload({prpEvent: {schema: "paperclip.prp.event.v2",@@ -95,7 +124,7 @@ describe("redaction", () => {},});expect((unknown?.prpEvent as Record<string, unknown>).eventType).toBe(- REDACTED_EVENT_VALUE,+ "session.not-a-real.event",);const mismatched = redactEventPayload({@@ -106,7 +135,7 @@ describe("redaction", () => {},});expect((mismatched?.prpEvent as Record<string, unknown>).eventType).toBe(- REDACTED_EVENT_VALUE,+ "session.capabilities.updated",);const secretPayload = redactEventPayload({@@ -189,7 +218,7 @@ describe("redaction", () => {const result = sanitizeRecord(input);expect(result.session).toBe(REDACTED_EVENT_VALUE);- expect(result.opaque).toBe(REDACTED_EVENT_VALUE);+ expect(result.opaque).toBe("aaa.bbb.ccc");expect(result.normal).toBe("plain");});@@ -208,7 +237,7 @@ describe("redaction", () => {nested: {schema: "paperclip.question_response.v1",runtimeSchema: "paperclip.runtime_request.v2",- arbitraryProviderValue: REDACTED_EVENT_VALUE,+ arbitraryProviderValue: "paperclip.question_set.v1",},});});@@ -225,7 +254,7 @@ describe("redaction", () => {schema: input.schema,nested: {runtimeSchema: input.nested.runtimeSchema,- providerValue: REDACTED_EVENT_VALUE,+ providerValue: input.nested.providerValue,},});expect(sanitizeRecord({ schema: "paperclip.native-execution-input.v4", runtimeSchema: "paperclip.native-model-envelope.v2" })).toEqual({@@ -258,28 +287,28 @@ describe("redaction", () => {schemaVersion: 1,eventType: "tool.execution.started",payload: {- eventType: REDACTED_EVENT_VALUE,+ eventType: "run.result.accepted",credential: REDACTED_EVENT_VALUE,},},unrelated: {- eventType: REDACTED_EVENT_VALUE,+ eventType: "workspace.file.referenced",},});expect(redactEventPayload(sanitized)).toEqual(sanitized);});- it("redacts unknown dotted event values even in a PRP-shaped envelope", () => {+ it("preserves unknown dotted event values instead of treating them as JWTs", () => {expect(redactEventPayload({schema: "paperclip.prp.event.v1",schemaVersion: 1,eventType: "attacker.supplied.token",})?.eventType,- ).toBe(REDACTED_EVENT_VALUE);+ ).toBe("attacker.supplied.token");});- it("does not trust discriminators inside a forged unknown schema", () => {+ it("preserves dotted schema identifiers without interpreting their authority", () => {expect(redactEventPayload({schema: "paperclip.attacker.control.v1",@@ -288,14 +317,14 @@ describe("redaction", () => {eventType: "tool.execution.started",}),).toEqual({- schema: REDACTED_EVENT_VALUE,- runtimeSchema: REDACTED_EVENT_VALUE,+ schema: "paperclip.attacker.control.v1",+ runtimeSchema: "paperclip.attacker.runtime.v1",schemaVersion: 1,- eventType: REDACTED_EVENT_VALUE,+ eventType: "tool.execution.started",});});- it("preserves native run span identities without weakening hostname redaction", () => {+ it("preserves native run span identities and ordinary hostnames", () => {const spanNames = ["environment.workspace.realize","native.coordinator.claim",@@ -326,7 +355,7 @@ describe("redaction", () => {schema: input.schema,span,parentSpan: "native.session.execute",- providerHostname: REDACTED_EVENT_VALUE,+ providerHostname: "api.openai.com",});expect(redactEventPayload(sanitized)).toEqual(sanitized);}@@ -336,13 +365,13 @@ describe("redaction", () => {schema: "paperclip.run-performance-span.v1",span: "api.openai.com",})?.span,- ).toBe(REDACTED_EVENT_VALUE);+ ).toBe("api.openai.com");expect(redactEventPayload({schema: "paperclip.run-performance-span.v1",span: "runner.example.com",})?.span,- ).toBe(REDACTED_EVENT_VALUE);+ ).toBe("runner.example.com");});it("redacts payload objects while preserving null", () => {@@ -374,7 +403,7 @@ describe("redaction", () => {details: ["safe context",`proxyAuthorization ${REDACTED_EVENT_VALUE}`,- REDACTED_EVENT_VALUE,+ "aaa.bbb.ccc",[`Bearer ${REDACTED_EVENT_VALUE}`],],},diff --git a/server/src/__tests__/remote-mcp-redaction.test.ts b/server/src/__tests__/remote-mcp-redaction.test.tsindex 65fa64b4ee..79d88a18fa 100644--- a/server/src/__tests__/remote-mcp-redaction.test.ts+++ b/server/src/__tests__/remote-mcp-redaction.test.ts@@ -2,11 +2,11 @@ import { describe, expect, it } from "vitest";import { redactEventPayload, redactSensitiveText } from "../redaction.js";describe("public Executor selectors and secret redaction", () => {- it("keeps only exact known public helper addresses readable in MCP results", () => {+ it("preserves dotted helper addresses without treating them as credentials", () => {const path = "executor.coreTools.integrations.list";expect(redactEventPayload({ path, text: `Call tools.${path}({})` })).toEqual({ path, text: `Call tools.${path}({})` });- expect(redactSensitiveText(`${path}.privateSecretSuffix`)).toContain("REDACTED");- expect(redactEventPayload({ path: "arbitrary.provider.path" })?.path).toContain("REDACTED");+ expect(redactSensitiveText(`${path}.privateSecretSuffix`)).toBe(`${path}.privateSecretSuffix`);+ expect(redactEventPayload({ path: "arbitrary.provider.path" })?.path).toBe("arbitrary.provider.path");});it("still redacts secret fields, bearer values, and JWT-shaped strings", () => {const value = "executor.coreTools.integrations.list";diff --git a/server/src/__tests__/tool-gateway.test.ts b/server/src/__tests__/tool-gateway.test.tsindex ee91153c37..ee0c57d698 100644--- a/server/src/__tests__/tool-gateway.test.ts+++ b/server/src/__tests__/tool-gateway.test.ts@@ -2836,7 +2836,7 @@ rl.on("line", (line) => {.where(eq(activityLog.action, "tool_gateway.call_completed"));expect(activity.details).toMatchObject({headerSummary: {- credentialHeaderNames: "***REDACTED***",+ credentialHeaderNames: ["authorization"],passthroughHeaderNames: ["x-client-request-id"],droppedPassthroughHeaderNames: expect.arrayContaining(["authorization",@@ -2930,7 +2930,7 @@ rl.on("line", (line) => {.where(eq(activityLog.action, "tool_gateway.call_completed"));expect(activity.details).toMatchObject({headerSummary: {- credentialHeaderNames: "***REDACTED***",+ credentialHeaderNames: [],passthroughHeaderNames: ["x-client-request-id"],droppedPassthroughHeaderNames: expect.arrayContaining(["authorization",diff --git a/server/src/redaction.ts b/server/src/redaction.tsindex b56287a611..31a7917a5d 100644--- a/server/src/redaction.ts+++ b/server/src/redaction.ts@@ -1,9 +1,9 @@import { redactCommandText } from "@paperclipai/adapter-utils";-import { isPublicExecutorToolSelector } from "@paperclipai/adapter-utils/command-redaction";+import { isPublicExecutorToolSelector, looksLikeCredentialJwt } from "@paperclipai/adapter-utils/command-redaction";-const SECRET_FIELD_NAME_PATTERN = String.raw`[A-Za-z0-9_-]*(?:api[-_]?key|access[-_]?token|auth(?:_?token)?|token|authorization|bearer|secret|passwd|password|credential|jwt|private[-_]?key|cookie|connectionstring|browser[-_]?code|login[-_]?url)[A-Za-z0-9_-]*`;+const SECRET_FIELD_NAME_PATTERN = String.raw`[A-Za-z0-9_-]*(?:api[-_]?key|access[-_]?token|auth(?:_?token)?|token|authorization(?:[-_]?code)?|bearer|secrets?|passwd|passwords?|credentials?|jwt|private[-_]?key|cookie|connectionstring|browser[-_]?code|login[-_]?url)(?:[-_]?(?:value|header|prod(?:uction)?|dev(?:elopment)?|test|staging|primary|secondary))*`;-const SECRET_PAYLOAD_KEY_RE = new RegExp(SECRET_FIELD_NAME_PATTERN, "i");+const SECRET_PAYLOAD_KEY_RE = new RegExp(`^(?:${SECRET_FIELD_NAME_PATTERN})(?:_plain|_ref)?$`, "i");// Authorization reasons are policy decision codes, not credentials. They must// remain visible in audit receipts even though the field name contains// "authorization". JWT-shaped values are still caught by the value guard below.@@ -44,12 +44,8 @@ function isAuditCountField(key: string, value: unknown): boolean {const COMMAND_PAYLOAD_KEY_RE =/(^command$|^cmd$|command[-_]?line|resolved[-_]?command|PAPERCLIP_RESOLVED_COMMAND)/i;const COMMAND_ARGS_PAYLOAD_KEY_RE = /^(commandArgs|command_?args|argv)$/i;-const JWT_VALUE_RE =- /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?$/;-// Durable protocol schema identifiers share JWT's broad dotted shape but are-// public discriminators, not credentials. Exempt the Paperclip schema-// namespace only in fields that actually declare a schema; the same value in-// arbitrary provider data remains subject to the fail-closed JWT guard.+// Public protocol discriminators are retained verbatim. A dotted identifier+// alone is not a credential; JWT detection requires an encoded JSON header.const PAPERCLIP_SCHEMA_FIELDS = new Set(["schema", "runtimeSchema"]);export const PAPERCLIP_PUBLIC_SCHEMA_IDS = new Set(["paperclip.artifact.generated.v1",@@ -712,6 +708,10 @@ function redactStandaloneBearerCredentials(input: string): string {}}+ const candidate = input.slice(credentialStart, end);+ // Preserve known authentication terms after bearer, unless explicitly quoted.+ // Named Authorization fields are already handled independently above.+ if (/^(?:tokens?|authentication|authorization|credentials?|schemes?|flows?)[.,;:!?]?$/i.test(candidate)) continue;if (credentialStart < copiedThrough) continue;parts.push(input.slice(copiedThrough, credentialStart), replacement);copiedThrough = end;@@ -738,7 +738,7 @@ function sanitizeValue(value: unknown): unknown {// string leaf after validated protocol discriminators have had a chance to// opt in above in sanitizeRecord.if (typeof value === "string") {- return JWT_VALUE_RE.test(value) && !isPublicExecutorToolSelector(value)+ return looksLikeCredentialJwt(value) && !isPublicExecutorToolSelector(value)? REDACTED_EVENT_VALUE: redactSensitiveText(value);}@@ -892,7 +892,7 @@ export function sanitizeRecord(continue;}if (- SECRET_PAYLOAD_KEY_RE.test(key) &&+ (SECRET_PAYLOAD_KEY_RE.test(key) || AUDIT_COUNT_PAYLOAD_KEYS.has(key)) &&!AUDIT_REASON_PAYLOAD_KEY_RE.test(key) &&!isAuditCountField(key, value)) {@@ -911,9 +911,7 @@ export function sanitizeRecord(redacted[key] = REDACTED_EVENT_VALUE;continue;}- // Interpret a validated schema field before applying generic value-shape- // heuristics. The exemption is deliberately closed to this one PRP v1- // discriminator; the same dotted string in any other field is redacted.+ // Preserve public protocol identities before scanning diagnostic values.if (isKnownPrpEventDiscriminator(record, key, value)) {redacted[key] = value;continue;@@ -928,7 +926,7 @@ export function sanitizeRecord(}if (typeof value === "string" &&- JWT_VALUE_RE.test(value) &&+ looksLikeCredentialJwt(value) &&!isPublicExecutorToolSelector(value) &&!isPaperclipSchemaDiscriminator(key, value)) {diff --git a/server/src/services/heartbeat.ts b/server/src/services/heartbeat.tsindex ca08e34d3c..f2abc881ff 100644--- a/server/src/services/heartbeat.ts+++ b/server/src/services/heartbeat.ts@@ -8812,7 +8812,7 @@ export function buildPaperclipTaskMarkdown(input: {"","Task title directive:","The current title is a provisional slice of the user's prompt. As one of your first tool calls, use set_task_title with a concise title describing the requested outcome and onlyIfProvisional: true. If that tool is unavailable, PUT /api/issues/" + issue.id + "/title with {title, onlyIfProvisional: true} using your normal Paperclip authentication. Do this in Ask and Plan modes too. Preserve the full task description and any title already chosen by the user; then continue the task.",- "Check the title tool result. If its wording is rejected as credential material, retry once with a shorter, plain-language title that keeps the task's meaning and contains no secret values. Use a new idempotency key for changed arguments. Do not treat a rejected call as a saved title.",+ "Check the title tool result before claiming the title was saved. Use a new idempotency key if retrying with changed arguments.",);}if (issue.conversationAgentId) {diff --git a/server/src/services/native-runtime/paperclip-runner-tool-authority.test.ts b/server/src/services/native-runtime/paperclip-runner-tool-authority.test.tsindex 96f4c5243b..ce29a7f4e0 100644--- a/server/src/services/native-runtime/paperclip-runner-tool-authority.test.ts+++ b/server/src/services/native-runtime/paperclip-runner-tool-authority.test.ts@@ -28,6 +28,7 @@ import { READ_CURRENT_WAKE_COMMENTS_TOOL_NAME } from "./current-wake-comments.jsimport { CAPABILITY_SEMANTIC_TOOL_CATALOG, runnerCodexDynamicToolsFit } from "../../vendor/paperclip-runner/index.js";describe("PaperclipRunnerToolAuthority", () => {+ const credentialDocumentBody = "Use a secret manager for credential handling.\nAuthorization: Bearer intentional-document-credential";let temporary: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;@@ -802,6 +803,7 @@ describe("PaperclipRunnerToolAuthority", () => {});it("writes a real revisioned document and replays the mutation receipt", async () => {+ const body = credentialDocumentBody;const authority = new PaperclipRunnerToolAuthority(db, {companyId,agentId,@@ -815,7 +817,7 @@ describe("PaperclipRunnerToolAuthority", () => {idempotencyKey: "write-plan-1",key: "plan",title: "Execution plan",- body: "Use the real document service.",+ body,// Provider bridges may serialize nullable string inputs as the literal// "null". The protocol boundary treats that as document creation.baseRevisionId: "null",@@ -831,7 +833,7 @@ describe("PaperclipRunnerToolAuthority", () => {expect(first).toMatchObject({disposition: "applied",created: true,- document: { key: "plan", body: "Use the real document service." },+ document: { key: "plan", body },});expect(await db@@ -839,6 +841,8 @@ describe("PaperclipRunnerToolAuthority", () => {.from(documents).where(eq(documents.companyId, companyId)),).toHaveLength(1);+ expect(await documentService(db).getIssueDocumentByKey(issueId, "plan"))+ .toMatchObject({ body: credentialDocumentBody });const documentActivity = await db.select().from(activityLog)@@ -960,7 +964,7 @@ describe("PaperclipRunnerToolAuthority", () => {documentId: plan!.id,revisionId: plan!.latestRevisionId,revisionNumber: plan!.latestRevisionNumber,- markdown: "Use the real document service.",+ markdown: credentialDocumentBody,},});});