@node9/policy-engine 2.33.0 → 2.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1211,6 +1211,69 @@ declare function isLoopbackHost(host: string): boolean;
1211
1211
  declare function gitRepoPath(url: string): string | null;
1212
1212
  declare function isDestructiveToolName(bareTool: string): boolean;
1213
1213
 
1214
+ /** The value as the gate compares it: email lower-cased, IBAN and account
1215
+ * upper-cased without spaces, host lower-cased. */
1216
+ declare function normalizeDestination(dest: string): string;
1217
+ /** 'iban:GB82 **** **** 5432', 'account:****5432', 'email:d***@acme.example';
1218
+ * a host (or anything else) is returned normalised and otherwise unchanged. */
1219
+ declare function maskDestination(dest: string): string;
1220
+ /** Whether a destination's kind is masked outside the machine. */
1221
+ declare function isMaskedKind(dest: string): boolean;
1222
+ /** SHA-256 (hex) of the normalised destination, kind prefix included. */
1223
+ declare function hashDestination(dest: string): string;
1224
+ /** Whether `entry` is a stored masked entry ('<masked>#sha256:<hex>'). */
1225
+ declare function isHashedEntry(entry: string): boolean;
1226
+ /** A full destination as it is stored on a trusted list outside the machine:
1227
+ * a masked kind becomes '<masked>#sha256:<hex>', a host stays as it is. */
1228
+ declare function trustedEntryOf(dest: string): string;
1229
+ /** Does a full destination match a stored entry (a hashed one, or a plain
1230
+ * value as the local list and older managed lists hold)? */
1231
+ declare function matchesTrustedEntry(dest: string, entry: string): boolean;
1232
+ /** Does a full destination match any entry of a list? Hashes it once. */
1233
+ declare function matchesTrustedList(dest: string, entries: readonly string[]): boolean;
1234
+ /**
1235
+ * A recipient as a person types it, in the stored destination form: an
1236
+ * address becomes `email:`, an IBAN `iban:`, a URL or hostname `host:`, and
1237
+ * `account:<number>` keeps its kind. A value that carries its kind is checked
1238
+ * against it. Null for anything else (a bare word, two values in one).
1239
+ */
1240
+ declare function normalizeRecipient(raw: unknown): string | null;
1241
+ /**
1242
+ * One entry of a trusted list outside the machine (the dashboard's workspace
1243
+ * list, the snapshot's personal list): a host in full; an address, IBAN or
1244
+ * account as '<masked>#sha256:<hex>'. A value already in that form passes
1245
+ * with its hash lower-cased; a full value is turned into it. Null when it is
1246
+ * neither. The backend mirror asserts the same vectors.
1247
+ */
1248
+ declare function normalizeTrustedEntry(raw: unknown): string | null;
1249
+ /** What a person reads for an entry: the masked part, without the hash. */
1250
+ declare function entryDisplay(entry: string): string;
1251
+ /**
1252
+ * IBANs (mod-97), card numbers (the detector's patterns and Luhn check),
1253
+ * account numbers (a whole IBAN-shaped value, or a number under an account
1254
+ * key) and email addresses inside a text, masked the way destinations are.
1255
+ * Masking is stricter than detection: a card is masked even where detectPii
1256
+ * exempts it as the fractional part of a number ("1.<card>", "0,<card>"),
1257
+ * since a hidden fraction in a log costs nothing and a shown card leaks; so
1258
+ * a Luhn-valid fractional part inside text is masked too. No quote or
1259
+ * backslash is introduced or removed, so a JSON string stays a JSON string;
1260
+ * a card written as a bare JSON number does not stay a number, so arguments
1261
+ * go through maskPersonalValue instead.
1262
+ */
1263
+ declare function maskPersonalData(text: string): string;
1264
+ /**
1265
+ * maskPersonalData over a JSON-shaped value (tool arguments), leaf by leaf, so
1266
+ * the result is always a value. A string leaf is masked twice: as raw text
1267
+ * first (a real newline or tab stays a word boundary, so a card or IBAN that
1268
+ * begins a line is found, as detectArgsPii finds it), then in its JSON form
1269
+ * under its own key (the account-key and whole-value rules see both). An
1270
+ * object key is masked as text; two keys that mask alike are told apart by a
1271
+ * `#2`, `#3` suffix so no entry is lost. A number whose text holds a card
1272
+ * becomes the masked string; a fraction stays the same number. Anything
1273
+ * deeper than 64 levels is replaced by '[REDACTED]'. Pure, never throws.
1274
+ */
1275
+ declare function maskPersonalValue(value: unknown): unknown;
1276
+
1214
1277
  interface ShellExposure {
1215
1278
  /** The command brings outside content in: its output is a source. */
1216
1279
  fetches: boolean;
@@ -1950,7 +2013,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
1950
2013
  * and fails CI when the hash drifts without a version bump — forgetting
1951
2014
  * is loud, not silent.
1952
2015
  */
1953
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v26";
2016
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
1954
2017
  /**
1955
2018
  * SHA-256 prefix of the detector-source files
1956
2019
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -1961,7 +2024,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v26";
1961
2024
  * files changed, this hash must change too, and you must consciously
1962
2025
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
1963
2026
  */
1964
- declare const CANONICAL_EXTRACTOR_HASH = "dec8c65145686360";
2027
+ declare const CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
1965
2028
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
1966
2029
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
1967
2030
  /**
@@ -2070,4 +2133,4 @@ declare function scanArgumentSecrets(args: unknown): DlpMatch | null;
2070
2133
  /** Engine version stamped on audit entries for future drift detection. */
2071
2134
  declare const ENGINE_VERSION = "1.4.0";
2072
2135
 
2073
- export { AGENT_INSTRUCTION_DIRS, AGENT_INSTRUCTION_FILES, ARGUMENT_SCAN_LIMITS, AST_FS_REGEX_RULES, type ArgumentInspectionResult, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_DANGEROUS_WORDS, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANARY_MIN_LENGTH, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, CHECKS, CHECK_BY_ID, CHECK_GROUPS, CHECK_TEXT, CHECK_VERDICT_RANK, COMMAND_WRAPPERS, CONFIGURABLE_CHECK_IDS, COPY_VERBS, COST_PER_LOOP_ITER_USD, type CanaryHit, type CanaryValue, type CanaryView, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, type CatalogSettings, type CheckDef, type CheckGroup, type CheckSource, type CheckText, DEFAULT_EGRESS_ALLOWLIST, DESTINATION_ARGS, DESTRUCTIVE_OP_RE, DLP_PATTERNS, DLP_SCAN_LIMITS, type Destination, type DestinationKind, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, FS_READ_TOOLS, type FileAccess, type FileAccessContext, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, type InspectionInput, type InspectionLayers, KNOB_GOVERNED, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LegacyPolicyKnobs, type LoopWindowEvaluation, MAP_GOVERNED, MAX_BLAST_PATH, MAX_DESTINATIONS, NET_BINARIES, PATTERN_VERB_NAMES, PRIVILEGE_ESCALATION_RE, type PackageEcosystem, type PackageInstallRequest, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type PositionedArg, type ProtectedFileVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type ResolvedCheck, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, SSRF_MAX_HOST, STARTUP_NAMES, SYSTEM_AUTH_DIRS, SYSTEM_AUTH_FILES, type ScanFinding, type ScanSignals, type ScanSummary, type ScanView, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestToken, type ShellDestination, type ShellExposure, type ShellInputResolution, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type SsrfFloorOptions, type SsrfMatch, type SsrfTier, type SsrfVerdict, TUNING_FIELDS, type ToolCallEntry, type ToolCallRecord, type ToolInspection, type ToolInspectionEntry, type TuningField, VERDICTS, type Verdict, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, catalogSettingsFromConfig, checkDangerousSql, checkIdForCheckedBy, checkIdForRule, checkToLegacyPolicy, checkValue, checksFromLegacyPolicy, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, classifyShellExposure, classifySsrf, collectFileAccesses, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, configurableValues, decodeEmbeddedBase64, decodeEmbeddedHex, dedupeCanonicalFindings, destinationDomain, destinationKind, destinationValue, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectInlineExec, detectPii, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateProtectedFileAccess, evaluateSmartConditions, extractAllSshHosts, extractArgDestinations, extractCanonicalFindings, extractContentDestinations, extractNetworkTargets, extractPackageInstalls, extractPositionalArgs, extractSessionLevelFindings, extractShellDestTokens, extractShellDestinations, extractToolDestinations, fileOperandFlagsOf, fileToolOperation, foldHomoglyphs, getCheck, getCompiledRegex, getNestedValue, gitRepoPath, hostMatches, incompleteFileVerdict, inspectArgumentSecrets, inspectionEntry, inspectionLayers, isAgentInstructionPath, isBashTool, isDestructiveToolName, isIgnoredTool, isInside, isKnobGoverned, isLegacySystemPath, isLockedCheck, isLoopbackHost, isPasswordHashPath, isPrivateHost, isProtectedHomePath, isShellShapedTool, isShieldVerdict, isStrictGatedTier, isVerdict, matchCanary, matchCanaryArgs, matchSensitivePath, matchesPattern, narrativeRuleLabel, normalizeCommandForPolicy, normalizeFilePath, normalizeForScan, normalizeIpLiteral, normalizePyPiName, parseAllSshHostsFromCommand, parseDestHost, patternShapeOf, positionedArgs, previewArgs, redactText, resolveAllChecks, resolveCheck, resolveCheckMap, resolvePinned, resolveShellInput, safeMessage, sampleCopyCommand, scanArgs, scanArgumentSecrets, scanInjection, scanText, scanViews, sensitivePathMatch, shellRuleArgs, ssrfCheckId, ssrfDestinationFloor, ssrfExemptMatches, ssrfFloor, ssrfReason, stripControlChars, stripInvisible, stripTerminalEscapes, summarizeBlast, summarizeScan, toScanFinding, toolMatchesRule, truncateBlastPath, tuningFromLegacyPolicy, tuningToLegacyPolicy, unwrapCommandHead, validateOverrides, validateRegex, validateShieldDefinition };
2136
+ export { AGENT_INSTRUCTION_DIRS, AGENT_INSTRUCTION_FILES, ARGUMENT_SCAN_LIMITS, AST_FS_REGEX_RULES, type ArgumentInspectionResult, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_DANGEROUS_WORDS, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANARY_MIN_LENGTH, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, CHECKS, CHECK_BY_ID, CHECK_GROUPS, CHECK_TEXT, CHECK_VERDICT_RANK, COMMAND_WRAPPERS, CONFIGURABLE_CHECK_IDS, COPY_VERBS, COST_PER_LOOP_ITER_USD, type CanaryHit, type CanaryValue, type CanaryView, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, type CatalogSettings, type CheckDef, type CheckGroup, type CheckSource, type CheckText, DEFAULT_EGRESS_ALLOWLIST, DESTINATION_ARGS, DESTRUCTIVE_OP_RE, DLP_PATTERNS, DLP_SCAN_LIMITS, type Destination, type DestinationKind, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, FS_READ_TOOLS, type FileAccess, type FileAccessContext, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, type InspectionInput, type InspectionLayers, KNOB_GOVERNED, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LegacyPolicyKnobs, type LoopWindowEvaluation, MAP_GOVERNED, MAX_BLAST_PATH, MAX_DESTINATIONS, NET_BINARIES, PATTERN_VERB_NAMES, PRIVILEGE_ESCALATION_RE, type PackageEcosystem, type PackageInstallRequest, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type PositionedArg, type ProtectedFileVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type ResolvedCheck, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, SSRF_MAX_HOST, STARTUP_NAMES, SYSTEM_AUTH_DIRS, SYSTEM_AUTH_FILES, type ScanFinding, type ScanSignals, type ScanSummary, type ScanView, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestToken, type ShellDestination, type ShellExposure, type ShellInputResolution, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type SsrfFloorOptions, type SsrfMatch, type SsrfTier, type SsrfVerdict, TUNING_FIELDS, type ToolCallEntry, type ToolCallRecord, type ToolInspection, type ToolInspectionEntry, type TuningField, VERDICTS, type Verdict, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, catalogSettingsFromConfig, checkDangerousSql, checkIdForCheckedBy, checkIdForRule, checkToLegacyPolicy, checkValue, checksFromLegacyPolicy, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, classifyShellExposure, classifySsrf, collectFileAccesses, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, configurableValues, decodeEmbeddedBase64, decodeEmbeddedHex, dedupeCanonicalFindings, destinationDomain, destinationKind, destinationValue, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectInlineExec, detectPii, entryDisplay, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateProtectedFileAccess, evaluateSmartConditions, extractAllSshHosts, extractArgDestinations, extractCanonicalFindings, extractContentDestinations, extractNetworkTargets, extractPackageInstalls, extractPositionalArgs, extractSessionLevelFindings, extractShellDestTokens, extractShellDestinations, extractToolDestinations, fileOperandFlagsOf, fileToolOperation, foldHomoglyphs, getCheck, getCompiledRegex, getNestedValue, gitRepoPath, hashDestination, hostMatches, incompleteFileVerdict, inspectArgumentSecrets, inspectionEntry, inspectionLayers, isAgentInstructionPath, isBashTool, isDestructiveToolName, isHashedEntry, isIgnoredTool, isInside, isKnobGoverned, isLegacySystemPath, isLockedCheck, isLoopbackHost, isMaskedKind, isPasswordHashPath, isPrivateHost, isProtectedHomePath, isShellShapedTool, isShieldVerdict, isStrictGatedTier, isVerdict, maskDestination, maskPersonalData, maskPersonalValue, matchCanary, matchCanaryArgs, matchSensitivePath, matchesPattern, matchesTrustedEntry, matchesTrustedList, narrativeRuleLabel, normalizeCommandForPolicy, normalizeDestination, normalizeFilePath, normalizeForScan, normalizeIpLiteral, normalizePyPiName, normalizeRecipient, normalizeTrustedEntry, parseAllSshHostsFromCommand, parseDestHost, patternShapeOf, positionedArgs, previewArgs, redactText, resolveAllChecks, resolveCheck, resolveCheckMap, resolvePinned, resolveShellInput, safeMessage, sampleCopyCommand, scanArgs, scanArgumentSecrets, scanInjection, scanText, scanViews, sensitivePathMatch, shellRuleArgs, ssrfCheckId, ssrfDestinationFloor, ssrfExemptMatches, ssrfFloor, ssrfReason, stripControlChars, stripInvisible, stripTerminalEscapes, summarizeBlast, summarizeScan, toScanFinding, toolMatchesRule, truncateBlastPath, trustedEntryOf, tuningFromLegacyPolicy, tuningToLegacyPolicy, unwrapCommandHead, validateOverrides, validateRegex, validateShieldDefinition };
package/dist/index.d.ts CHANGED
@@ -1211,6 +1211,69 @@ declare function isLoopbackHost(host: string): boolean;
1211
1211
  declare function gitRepoPath(url: string): string | null;
1212
1212
  declare function isDestructiveToolName(bareTool: string): boolean;
1213
1213
 
1214
+ /** The value as the gate compares it: email lower-cased, IBAN and account
1215
+ * upper-cased without spaces, host lower-cased. */
1216
+ declare function normalizeDestination(dest: string): string;
1217
+ /** 'iban:GB82 **** **** 5432', 'account:****5432', 'email:d***@acme.example';
1218
+ * a host (or anything else) is returned normalised and otherwise unchanged. */
1219
+ declare function maskDestination(dest: string): string;
1220
+ /** Whether a destination's kind is masked outside the machine. */
1221
+ declare function isMaskedKind(dest: string): boolean;
1222
+ /** SHA-256 (hex) of the normalised destination, kind prefix included. */
1223
+ declare function hashDestination(dest: string): string;
1224
+ /** Whether `entry` is a stored masked entry ('<masked>#sha256:<hex>'). */
1225
+ declare function isHashedEntry(entry: string): boolean;
1226
+ /** A full destination as it is stored on a trusted list outside the machine:
1227
+ * a masked kind becomes '<masked>#sha256:<hex>', a host stays as it is. */
1228
+ declare function trustedEntryOf(dest: string): string;
1229
+ /** Does a full destination match a stored entry (a hashed one, or a plain
1230
+ * value as the local list and older managed lists hold)? */
1231
+ declare function matchesTrustedEntry(dest: string, entry: string): boolean;
1232
+ /** Does a full destination match any entry of a list? Hashes it once. */
1233
+ declare function matchesTrustedList(dest: string, entries: readonly string[]): boolean;
1234
+ /**
1235
+ * A recipient as a person types it, in the stored destination form: an
1236
+ * address becomes `email:`, an IBAN `iban:`, a URL or hostname `host:`, and
1237
+ * `account:<number>` keeps its kind. A value that carries its kind is checked
1238
+ * against it. Null for anything else (a bare word, two values in one).
1239
+ */
1240
+ declare function normalizeRecipient(raw: unknown): string | null;
1241
+ /**
1242
+ * One entry of a trusted list outside the machine (the dashboard's workspace
1243
+ * list, the snapshot's personal list): a host in full; an address, IBAN or
1244
+ * account as '<masked>#sha256:<hex>'. A value already in that form passes
1245
+ * with its hash lower-cased; a full value is turned into it. Null when it is
1246
+ * neither. The backend mirror asserts the same vectors.
1247
+ */
1248
+ declare function normalizeTrustedEntry(raw: unknown): string | null;
1249
+ /** What a person reads for an entry: the masked part, without the hash. */
1250
+ declare function entryDisplay(entry: string): string;
1251
+ /**
1252
+ * IBANs (mod-97), card numbers (the detector's patterns and Luhn check),
1253
+ * account numbers (a whole IBAN-shaped value, or a number under an account
1254
+ * key) and email addresses inside a text, masked the way destinations are.
1255
+ * Masking is stricter than detection: a card is masked even where detectPii
1256
+ * exempts it as the fractional part of a number ("1.<card>", "0,<card>"),
1257
+ * since a hidden fraction in a log costs nothing and a shown card leaks; so
1258
+ * a Luhn-valid fractional part inside text is masked too. No quote or
1259
+ * backslash is introduced or removed, so a JSON string stays a JSON string;
1260
+ * a card written as a bare JSON number does not stay a number, so arguments
1261
+ * go through maskPersonalValue instead.
1262
+ */
1263
+ declare function maskPersonalData(text: string): string;
1264
+ /**
1265
+ * maskPersonalData over a JSON-shaped value (tool arguments), leaf by leaf, so
1266
+ * the result is always a value. A string leaf is masked twice: as raw text
1267
+ * first (a real newline or tab stays a word boundary, so a card or IBAN that
1268
+ * begins a line is found, as detectArgsPii finds it), then in its JSON form
1269
+ * under its own key (the account-key and whole-value rules see both). An
1270
+ * object key is masked as text; two keys that mask alike are told apart by a
1271
+ * `#2`, `#3` suffix so no entry is lost. A number whose text holds a card
1272
+ * becomes the masked string; a fraction stays the same number. Anything
1273
+ * deeper than 64 levels is replaced by '[REDACTED]'. Pure, never throws.
1274
+ */
1275
+ declare function maskPersonalValue(value: unknown): unknown;
1276
+
1214
1277
  interface ShellExposure {
1215
1278
  /** The command brings outside content in: its output is a source. */
1216
1279
  fetches: boolean;
@@ -1950,7 +2013,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
1950
2013
  * and fails CI when the hash drifts without a version bump — forgetting
1951
2014
  * is loud, not silent.
1952
2015
  */
1953
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v26";
2016
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
1954
2017
  /**
1955
2018
  * SHA-256 prefix of the detector-source files
1956
2019
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -1961,7 +2024,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v26";
1961
2024
  * files changed, this hash must change too, and you must consciously
1962
2025
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
1963
2026
  */
1964
- declare const CANONICAL_EXTRACTOR_HASH = "dec8c65145686360";
2027
+ declare const CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
1965
2028
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
1966
2029
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
1967
2030
  /**
@@ -2070,4 +2133,4 @@ declare function scanArgumentSecrets(args: unknown): DlpMatch | null;
2070
2133
  /** Engine version stamped on audit entries for future drift detection. */
2071
2134
  declare const ENGINE_VERSION = "1.4.0";
2072
2135
 
2073
- export { AGENT_INSTRUCTION_DIRS, AGENT_INSTRUCTION_FILES, ARGUMENT_SCAN_LIMITS, AST_FS_REGEX_RULES, type ArgumentInspectionResult, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_DANGEROUS_WORDS, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANARY_MIN_LENGTH, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, CHECKS, CHECK_BY_ID, CHECK_GROUPS, CHECK_TEXT, CHECK_VERDICT_RANK, COMMAND_WRAPPERS, CONFIGURABLE_CHECK_IDS, COPY_VERBS, COST_PER_LOOP_ITER_USD, type CanaryHit, type CanaryValue, type CanaryView, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, type CatalogSettings, type CheckDef, type CheckGroup, type CheckSource, type CheckText, DEFAULT_EGRESS_ALLOWLIST, DESTINATION_ARGS, DESTRUCTIVE_OP_RE, DLP_PATTERNS, DLP_SCAN_LIMITS, type Destination, type DestinationKind, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, FS_READ_TOOLS, type FileAccess, type FileAccessContext, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, type InspectionInput, type InspectionLayers, KNOB_GOVERNED, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LegacyPolicyKnobs, type LoopWindowEvaluation, MAP_GOVERNED, MAX_BLAST_PATH, MAX_DESTINATIONS, NET_BINARIES, PATTERN_VERB_NAMES, PRIVILEGE_ESCALATION_RE, type PackageEcosystem, type PackageInstallRequest, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type PositionedArg, type ProtectedFileVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type ResolvedCheck, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, SSRF_MAX_HOST, STARTUP_NAMES, SYSTEM_AUTH_DIRS, SYSTEM_AUTH_FILES, type ScanFinding, type ScanSignals, type ScanSummary, type ScanView, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestToken, type ShellDestination, type ShellExposure, type ShellInputResolution, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type SsrfFloorOptions, type SsrfMatch, type SsrfTier, type SsrfVerdict, TUNING_FIELDS, type ToolCallEntry, type ToolCallRecord, type ToolInspection, type ToolInspectionEntry, type TuningField, VERDICTS, type Verdict, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, catalogSettingsFromConfig, checkDangerousSql, checkIdForCheckedBy, checkIdForRule, checkToLegacyPolicy, checkValue, checksFromLegacyPolicy, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, classifyShellExposure, classifySsrf, collectFileAccesses, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, configurableValues, decodeEmbeddedBase64, decodeEmbeddedHex, dedupeCanonicalFindings, destinationDomain, destinationKind, destinationValue, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectInlineExec, detectPii, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateProtectedFileAccess, evaluateSmartConditions, extractAllSshHosts, extractArgDestinations, extractCanonicalFindings, extractContentDestinations, extractNetworkTargets, extractPackageInstalls, extractPositionalArgs, extractSessionLevelFindings, extractShellDestTokens, extractShellDestinations, extractToolDestinations, fileOperandFlagsOf, fileToolOperation, foldHomoglyphs, getCheck, getCompiledRegex, getNestedValue, gitRepoPath, hostMatches, incompleteFileVerdict, inspectArgumentSecrets, inspectionEntry, inspectionLayers, isAgentInstructionPath, isBashTool, isDestructiveToolName, isIgnoredTool, isInside, isKnobGoverned, isLegacySystemPath, isLockedCheck, isLoopbackHost, isPasswordHashPath, isPrivateHost, isProtectedHomePath, isShellShapedTool, isShieldVerdict, isStrictGatedTier, isVerdict, matchCanary, matchCanaryArgs, matchSensitivePath, matchesPattern, narrativeRuleLabel, normalizeCommandForPolicy, normalizeFilePath, normalizeForScan, normalizeIpLiteral, normalizePyPiName, parseAllSshHostsFromCommand, parseDestHost, patternShapeOf, positionedArgs, previewArgs, redactText, resolveAllChecks, resolveCheck, resolveCheckMap, resolvePinned, resolveShellInput, safeMessage, sampleCopyCommand, scanArgs, scanArgumentSecrets, scanInjection, scanText, scanViews, sensitivePathMatch, shellRuleArgs, ssrfCheckId, ssrfDestinationFloor, ssrfExemptMatches, ssrfFloor, ssrfReason, stripControlChars, stripInvisible, stripTerminalEscapes, summarizeBlast, summarizeScan, toScanFinding, toolMatchesRule, truncateBlastPath, tuningFromLegacyPolicy, tuningToLegacyPolicy, unwrapCommandHead, validateOverrides, validateRegex, validateShieldDefinition };
2136
+ export { AGENT_INSTRUCTION_DIRS, AGENT_INSTRUCTION_FILES, ARGUMENT_SCAN_LIMITS, AST_FS_REGEX_RULES, type ArgumentInspectionResult, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_DANGEROUS_WORDS, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANARY_MIN_LENGTH, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, CHECKS, CHECK_BY_ID, CHECK_GROUPS, CHECK_TEXT, CHECK_VERDICT_RANK, COMMAND_WRAPPERS, CONFIGURABLE_CHECK_IDS, COPY_VERBS, COST_PER_LOOP_ITER_USD, type CanaryHit, type CanaryValue, type CanaryView, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, type CatalogSettings, type CheckDef, type CheckGroup, type CheckSource, type CheckText, DEFAULT_EGRESS_ALLOWLIST, DESTINATION_ARGS, DESTRUCTIVE_OP_RE, DLP_PATTERNS, DLP_SCAN_LIMITS, type Destination, type DestinationKind, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, FS_READ_TOOLS, type FileAccess, type FileAccessContext, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, type InspectionInput, type InspectionLayers, KNOB_GOVERNED, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LegacyPolicyKnobs, type LoopWindowEvaluation, MAP_GOVERNED, MAX_BLAST_PATH, MAX_DESTINATIONS, NET_BINARIES, PATTERN_VERB_NAMES, PRIVILEGE_ESCALATION_RE, type PackageEcosystem, type PackageInstallRequest, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type PositionedArg, type ProtectedFileVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type ResolvedCheck, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, SSRF_MAX_HOST, STARTUP_NAMES, SYSTEM_AUTH_DIRS, SYSTEM_AUTH_FILES, type ScanFinding, type ScanSignals, type ScanSummary, type ScanView, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestToken, type ShellDestination, type ShellExposure, type ShellInputResolution, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type SsrfFloorOptions, type SsrfMatch, type SsrfTier, type SsrfVerdict, TUNING_FIELDS, type ToolCallEntry, type ToolCallRecord, type ToolInspection, type ToolInspectionEntry, type TuningField, VERDICTS, type Verdict, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, catalogSettingsFromConfig, checkDangerousSql, checkIdForCheckedBy, checkIdForRule, checkToLegacyPolicy, checkValue, checksFromLegacyPolicy, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, classifyShellExposure, classifySsrf, collectFileAccesses, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, configurableValues, decodeEmbeddedBase64, decodeEmbeddedHex, dedupeCanonicalFindings, destinationDomain, destinationKind, destinationValue, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectInlineExec, detectPii, entryDisplay, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateProtectedFileAccess, evaluateSmartConditions, extractAllSshHosts, extractArgDestinations, extractCanonicalFindings, extractContentDestinations, extractNetworkTargets, extractPackageInstalls, extractPositionalArgs, extractSessionLevelFindings, extractShellDestTokens, extractShellDestinations, extractToolDestinations, fileOperandFlagsOf, fileToolOperation, foldHomoglyphs, getCheck, getCompiledRegex, getNestedValue, gitRepoPath, hashDestination, hostMatches, incompleteFileVerdict, inspectArgumentSecrets, inspectionEntry, inspectionLayers, isAgentInstructionPath, isBashTool, isDestructiveToolName, isHashedEntry, isIgnoredTool, isInside, isKnobGoverned, isLegacySystemPath, isLockedCheck, isLoopbackHost, isMaskedKind, isPasswordHashPath, isPrivateHost, isProtectedHomePath, isShellShapedTool, isShieldVerdict, isStrictGatedTier, isVerdict, maskDestination, maskPersonalData, maskPersonalValue, matchCanary, matchCanaryArgs, matchSensitivePath, matchesPattern, matchesTrustedEntry, matchesTrustedList, narrativeRuleLabel, normalizeCommandForPolicy, normalizeDestination, normalizeFilePath, normalizeForScan, normalizeIpLiteral, normalizePyPiName, normalizeRecipient, normalizeTrustedEntry, parseAllSshHostsFromCommand, parseDestHost, patternShapeOf, positionedArgs, previewArgs, redactText, resolveAllChecks, resolveCheck, resolveCheckMap, resolvePinned, resolveShellInput, safeMessage, sampleCopyCommand, scanArgs, scanArgumentSecrets, scanInjection, scanText, scanViews, sensitivePathMatch, shellRuleArgs, ssrfCheckId, ssrfDestinationFloor, ssrfExemptMatches, ssrfFloor, ssrfReason, stripControlChars, stripInvisible, stripTerminalEscapes, summarizeBlast, summarizeScan, toScanFinding, toolMatchesRule, truncateBlastPath, trustedEntryOf, tuningFromLegacyPolicy, tuningToLegacyPolicy, unwrapCommandHead, validateOverrides, validateRegex, validateShieldDefinition };
package/dist/index.js CHANGED
@@ -111,6 +111,7 @@ __export(src_exports, {
111
111
  detectDangerousShellExec: () => detectDangerousShellExec,
112
112
  detectInlineExec: () => detectInlineExec,
113
113
  detectPii: () => detectPii,
114
+ entryDisplay: () => entryDisplay,
114
115
  evaluateEgress: () => evaluateEgress,
115
116
  evaluateLoopWindow: () => evaluateLoopWindow,
116
117
  evaluatePolicy: () => evaluatePolicy,
@@ -134,6 +135,7 @@ __export(src_exports, {
134
135
  getCompiledRegex: () => getCompiledRegex,
135
136
  getNestedValue: () => getNestedValue,
136
137
  gitRepoPath: () => gitRepoPath,
138
+ hashDestination: () => hashDestination,
137
139
  hostMatches: () => hostMatches,
138
140
  incompleteFileVerdict: () => incompleteFileVerdict,
139
141
  inspectArgumentSecrets: () => inspectArgumentSecrets,
@@ -142,12 +144,14 @@ __export(src_exports, {
142
144
  isAgentInstructionPath: () => isAgentInstructionPath,
143
145
  isBashTool: () => isBashTool,
144
146
  isDestructiveToolName: () => isDestructiveToolName,
147
+ isHashedEntry: () => isHashedEntry,
145
148
  isIgnoredTool: () => isIgnoredTool,
146
149
  isInside: () => isInside,
147
150
  isKnobGoverned: () => isKnobGoverned,
148
151
  isLegacySystemPath: () => isLegacySystemPath,
149
152
  isLockedCheck: () => isLockedCheck,
150
153
  isLoopbackHost: () => isLoopbackHost,
154
+ isMaskedKind: () => isMaskedKind,
151
155
  isPasswordHashPath: () => isPasswordHashPath,
152
156
  isPrivateHost: () => isPrivateHost,
153
157
  isProtectedHomePath: () => isProtectedHomePath,
@@ -155,16 +159,24 @@ __export(src_exports, {
155
159
  isShieldVerdict: () => isShieldVerdict,
156
160
  isStrictGatedTier: () => isStrictGatedTier,
157
161
  isVerdict: () => isVerdict,
162
+ maskDestination: () => maskDestination,
163
+ maskPersonalData: () => maskPersonalData,
164
+ maskPersonalValue: () => maskPersonalValue,
158
165
  matchCanary: () => matchCanary,
159
166
  matchCanaryArgs: () => matchCanaryArgs,
160
167
  matchSensitivePath: () => matchSensitivePath2,
161
168
  matchesPattern: () => matchesPattern,
169
+ matchesTrustedEntry: () => matchesTrustedEntry,
170
+ matchesTrustedList: () => matchesTrustedList,
162
171
  narrativeRuleLabel: () => narrativeRuleLabel,
163
172
  normalizeCommandForPolicy: () => normalizeCommandForPolicy,
173
+ normalizeDestination: () => normalizeDestination,
164
174
  normalizeFilePath: () => normalizeFilePath,
165
175
  normalizeForScan: () => normalizeForScan,
166
176
  normalizeIpLiteral: () => normalizeIpLiteral,
167
177
  normalizePyPiName: () => normalizePyPiName,
178
+ normalizeRecipient: () => normalizeRecipient,
179
+ normalizeTrustedEntry: () => normalizeTrustedEntry,
168
180
  parseAllSshHostsFromCommand: () => parseAllSshHostsFromCommand,
169
181
  parseDestHost: () => parseDestHost,
170
182
  patternShapeOf: () => patternShapeOf,
@@ -198,6 +210,7 @@ __export(src_exports, {
198
210
  toScanFinding: () => toScanFinding,
199
211
  toolMatchesRule: () => toolMatchesRule,
200
212
  truncateBlastPath: () => truncateBlastPath,
213
+ trustedEntryOf: () => trustedEntryOf,
201
214
  tuningFromLegacyPolicy: () => tuningFromLegacyPolicy,
202
215
  tuningToLegacyPolicy: () => tuningToLegacyPolicy,
203
216
  unwrapCommandHead: () => unwrapCommandHead,
@@ -11531,6 +11544,277 @@ function isDestructiveToolName(bareTool) {
11531
11544
  return DESTRUCTIVE_VERB_RE.test(bareTool);
11532
11545
  }
11533
11546
 
11547
+ // src/exposure/mask.ts
11548
+ var import_crypto2 = require("crypto");
11549
+
11550
+ // src/scan/pii.ts
11551
+ var PII_EMAIL_RE = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/;
11552
+ var PII_SSN_RE = /\b\d{3}-\d{2}-\d{4}\b/;
11553
+ var PII_PHONE_RE = /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/;
11554
+ var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|6\d{3})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/;
11555
+ var PII_CC15_RE = /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/;
11556
+ var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
11557
+ function* validCardRuns(text, base2, exemptFractions = true) {
11558
+ const re = new RegExp(base2.source, "g");
11559
+ let m;
11560
+ while ((m = re.exec(text)) !== null) {
11561
+ const digits = m[0].replace(/\D/g, "");
11562
+ const fraction = exemptFractions && isDecimalFraction(text, m.index, digits.length === m[0].length);
11563
+ if (!fraction && validateLuhn(digits)) {
11564
+ yield { index: m.index, length: m[0].length, digits };
11565
+ } else {
11566
+ re.lastIndex = m.index + 1;
11567
+ }
11568
+ }
11569
+ }
11570
+ function hasValidCard(text) {
11571
+ for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
11572
+ if (!validCardRuns(text, base2).next().done) return true;
11573
+ }
11574
+ return false;
11575
+ }
11576
+ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
11577
+ let out = text;
11578
+ for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
11579
+ let res = "";
11580
+ let last = 0;
11581
+ for (const run of validCardRuns(out, base2, exemptFractions)) {
11582
+ res += out.slice(last, run.index) + replace(run.digits);
11583
+ last = run.index + run.length;
11584
+ }
11585
+ out = res + out.slice(last);
11586
+ }
11587
+ return out;
11588
+ }
11589
+ var NUMBER_LEAD_RE = /[\s:=;([{"'+-]/;
11590
+ function isDecimalFraction(text, index, unseparated) {
11591
+ if (!unseparated) return false;
11592
+ const sep = text[index - 1];
11593
+ const a = text[index - 2];
11594
+ if (sep === ".") {
11595
+ if (a !== void 0 && a >= "0" && a <= "9") return true;
11596
+ return a === void 0 || NUMBER_LEAD_RE.test(a);
11597
+ }
11598
+ if (sep === "," && a === "0") {
11599
+ const b = text[index - 3];
11600
+ return b === void 0 || NUMBER_LEAD_RE.test(b);
11601
+ }
11602
+ return false;
11603
+ }
11604
+ function hasValidIban(text) {
11605
+ const re = new RegExp(PII_IBAN_RE.source, "g");
11606
+ let m;
11607
+ while ((m = re.exec(text)) !== null) {
11608
+ if (validateIban(m[0])) return true;
11609
+ re.lastIndex = m.index + 1;
11610
+ }
11611
+ return false;
11612
+ }
11613
+ function detectPii(text) {
11614
+ const found = /* @__PURE__ */ new Set();
11615
+ if (/@/.test(text) && PII_EMAIL_RE.test(text)) found.add("Email");
11616
+ if (/-/.test(text) && PII_SSN_RE.test(text)) found.add("SSN");
11617
+ if (PII_PHONE_RE.test(text)) found.add("Phone");
11618
+ if (hasValidCard(text)) found.add("Credit Card");
11619
+ if (hasValidIban(text)) found.add("IBAN");
11620
+ return [...found];
11621
+ }
11622
+ var REALTIME_PII_PATTERNS = ["SSN", "Credit Card", "IBAN"];
11623
+ var MAX_PII_SCAN_BYTES = 1e5;
11624
+ function* stringLeaves(v, depth = 0) {
11625
+ if (depth > 6) return;
11626
+ if (typeof v === "string") {
11627
+ if (v.length > 0) yield v;
11628
+ return;
11629
+ }
11630
+ if (typeof v === "number") {
11631
+ if (Number.isFinite(v)) yield String(v);
11632
+ return;
11633
+ }
11634
+ if (!v || typeof v !== "object") return;
11635
+ if (Array.isArray(v)) {
11636
+ for (const x of v) yield* stringLeaves(x, depth + 1);
11637
+ return;
11638
+ }
11639
+ for (const x of Object.values(v)) yield* stringLeaves(x, depth + 1);
11640
+ }
11641
+ function detectArgsPii(args) {
11642
+ if (args === null || args === void 0) return [];
11643
+ const found = /* @__PURE__ */ new Set();
11644
+ let budget = MAX_PII_SCAN_BYTES;
11645
+ try {
11646
+ for (const leaf of stringLeaves(args)) {
11647
+ if (budget <= 0) break;
11648
+ const t = leaf.length > budget ? leaf.slice(0, budget) : leaf;
11649
+ budget -= t.length;
11650
+ for (const p of detectPii(t)) {
11651
+ if (REALTIME_PII_PATTERNS.includes(p)) found.add(p);
11652
+ }
11653
+ }
11654
+ } catch {
11655
+ return [];
11656
+ }
11657
+ return [...found];
11658
+ }
11659
+
11660
+ // src/exposure/mask.ts
11661
+ var MASKED_KINDS = /* @__PURE__ */ new Set(["email", "iban", "account"]);
11662
+ var ENTRY_RE = /^(email|iban|account):([^#\s]{1,200}(?: [^#\s]{1,40}){0,4})#sha256:([0-9a-f]{64})$/;
11663
+ function split(dest) {
11664
+ const i = dest.indexOf(":");
11665
+ if (i <= 0) return null;
11666
+ return { kind: dest.slice(0, i).toLowerCase(), value: dest.slice(i + 1) };
11667
+ }
11668
+ function normalizeDestination(dest) {
11669
+ const p = split(dest.trim());
11670
+ if (!p) return dest.trim();
11671
+ if (p.kind === "iban" || p.kind === "account")
11672
+ return `${p.kind}:${p.value.replace(/\s+/g, "").toUpperCase()}`;
11673
+ return `${p.kind}:${p.value.toLowerCase()}`;
11674
+ }
11675
+ function maskEmailValue(address) {
11676
+ const at = address.lastIndexOf("@");
11677
+ if (at <= 0) return "***";
11678
+ return `${address[0]}***@${address.slice(at + 1)}`;
11679
+ }
11680
+ function maskDestination(dest) {
11681
+ const n = normalizeDestination(dest);
11682
+ const p = split(n);
11683
+ if (!p || !MASKED_KINDS.has(p.kind)) return n;
11684
+ if (p.kind === "iban") return `iban:${p.value.slice(0, 4)} **** **** ${p.value.slice(-4)}`;
11685
+ if (p.kind === "account") return `account:****${p.value.slice(-4)}`;
11686
+ return `email:${maskEmailValue(p.value)}`;
11687
+ }
11688
+ function isMaskedKind(dest) {
11689
+ const p = split(dest);
11690
+ return !!p && MASKED_KINDS.has(p.kind);
11691
+ }
11692
+ function hashDestination(dest) {
11693
+ return (0, import_crypto2.createHash)("sha256").update(normalizeDestination(dest), "utf8").digest("hex");
11694
+ }
11695
+ function isHashedEntry(entry) {
11696
+ return ENTRY_RE.test(entry);
11697
+ }
11698
+ function trustedEntryOf(dest) {
11699
+ const n = normalizeDestination(dest);
11700
+ if (!isMaskedKind(n)) return n;
11701
+ return `${maskDestination(n)}#sha256:${hashDestination(n)}`;
11702
+ }
11703
+ function matchesTrustedEntry(dest, entry) {
11704
+ const m = ENTRY_RE.exec(entry);
11705
+ if (m) return hashDestination(dest) === m[3];
11706
+ return normalizeDestination(dest) === normalizeDestination(entry);
11707
+ }
11708
+ function matchesTrustedList(dest, entries) {
11709
+ if (entries.length === 0) return false;
11710
+ const plain = normalizeDestination(dest);
11711
+ let hash2;
11712
+ for (const entry of entries) {
11713
+ const m = ENTRY_RE.exec(entry);
11714
+ if (m) {
11715
+ hash2 ??= hashDestination(dest);
11716
+ if (hash2 === m[3]) return true;
11717
+ } else if (plain === normalizeDestination(entry)) return true;
11718
+ }
11719
+ return false;
11720
+ }
11721
+ function normalizeRecipient(raw) {
11722
+ if (typeof raw !== "string") return null;
11723
+ const v = raw.trim();
11724
+ if (!v || v.length > 512) return null;
11725
+ const acct = /^account:([A-Za-z0-9 ]{8,40})$/i.exec(v);
11726
+ if (acct) {
11727
+ const n = acct[1].replace(/\s+/g, "").toUpperCase();
11728
+ return n.length >= 8 && n.length <= 34 ? `account:${n}` : null;
11729
+ }
11730
+ if (/^(email|host|iban):/i.test(v)) {
11731
+ const i = v.indexOf(":");
11732
+ const kind = v.slice(0, i).toLowerCase();
11733
+ const inner = normalizeRecipient(v.slice(i + 1));
11734
+ return inner && inner.startsWith(`${kind}:`) ? inner : null;
11735
+ }
11736
+ const found = extractArgDestinations({ to: v });
11737
+ return found.length === 1 ? found[0] : null;
11738
+ }
11739
+ function normalizeTrustedEntry(raw) {
11740
+ if (typeof raw !== "string") return null;
11741
+ const v = raw.trim().replace(/#sha256:([0-9A-Fa-f]{64})$/, (_m, h) => `#sha256:${h.toLowerCase()}`);
11742
+ if (v.includes("#")) return isHashedEntry(v) ? v : null;
11743
+ const full = normalizeRecipient(v);
11744
+ return full === null ? null : trustedEntryOf(full);
11745
+ }
11746
+ function entryDisplay(entry) {
11747
+ const i = entry.indexOf("#sha256:");
11748
+ return i > 0 ? entry.slice(0, i) : entry;
11749
+ }
11750
+ var IBAN_TEXT_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/gi;
11751
+ var EMAIL_TEXT_RE = /[\p{L}\p{N}._%+-]+@[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?(?:\.[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?)*\.\p{L}{2,}/gu;
11752
+ var ACCOUNT_KEY_RE = /("(?:iban|account|account_number|accountNumber)"\s*:\s*")([A-Za-z0-9 .-]{6,40})(")/g;
11753
+ var ACCOUNT_VALUE_RE = /"([A-Z]{2}\d{2}[A-Z0-9]{11,30})"/g;
11754
+ function maskPersonalData(text) {
11755
+ return maskText(text, false);
11756
+ }
11757
+ function maskText(text, exemptFractions) {
11758
+ if (!text) return text;
11759
+ try {
11760
+ let out = text;
11761
+ out = out.replace(IBAN_TEXT_RE, (m) => {
11762
+ const v = m.replace(/[ -]/g, "").toUpperCase();
11763
+ return validateIban(v) ? `${v.slice(0, 4)} **** **** ${v.slice(-4)}` : m;
11764
+ });
11765
+ out = replaceValidCards(out, (digits) => `**** **** **** ${digits.slice(-4)}`, {
11766
+ exemptFractions
11767
+ });
11768
+ out = out.replace(
11769
+ ACCOUNT_VALUE_RE,
11770
+ (m, v) => IBAN_LENGTH[v.slice(0, 2).toUpperCase()] === v.length ? `"****${v.slice(-4)}"` : m
11771
+ );
11772
+ out = out.replace(ACCOUNT_KEY_RE, (m, a, v, b) => {
11773
+ const compact = v.replace(/[ .-]/g, "");
11774
+ const digits = compact.replace(/\D/g, "").length;
11775
+ return digits >= 6 && digits * 2 >= compact.length ? `${a}****${compact.slice(-4)}${b}` : m;
11776
+ });
11777
+ if (out.includes("@")) out = out.replace(EMAIL_TEXT_RE, (m) => maskEmailValue(m));
11778
+ return out;
11779
+ } catch {
11780
+ return text;
11781
+ }
11782
+ }
11783
+ var MAX_MASK_DEPTH = 64;
11784
+ function maskPersonalValue(value) {
11785
+ return maskLeaf(value, "", 0);
11786
+ }
11787
+ function maskLeaf(value, key, depth) {
11788
+ if (depth > MAX_MASK_DEPTH) return "[REDACTED]";
11789
+ if (typeof value === "string") {
11790
+ try {
11791
+ const json = `{${JSON.stringify(key)}:${JSON.stringify(maskPersonalData(value))}}`;
11792
+ return Object.values(JSON.parse(maskPersonalData(json)))[0];
11793
+ } catch {
11794
+ return "[REDACTED]";
11795
+ }
11796
+ }
11797
+ if (typeof value === "number") {
11798
+ const text = String(value);
11799
+ const masked = maskText(text, true);
11800
+ return masked === text ? value : masked;
11801
+ }
11802
+ if (Array.isArray(value)) return value.map((v) => maskLeaf(v, key, depth + 1));
11803
+ if (value && typeof value === "object") {
11804
+ const used = /* @__PURE__ */ new Set();
11805
+ return Object.fromEntries(
11806
+ Object.entries(value).map(([k, v]) => {
11807
+ const base2 = maskPersonalData(k);
11808
+ let name = base2;
11809
+ for (let n = 2; used.has(name); n++) name = `${base2}#${n}`;
11810
+ used.add(name);
11811
+ return [name, maskLeaf(v, k, depth + 1)];
11812
+ })
11813
+ );
11814
+ }
11815
+ return value;
11816
+ }
11817
+
11534
11818
  // src/exposure/shell.ts
11535
11819
  var import_mvdan_sh4 = __toESM(require("mvdan-sh"));
11536
11820
  var { syntax: syntax4 } = import_mvdan_sh4.default;
@@ -12011,11 +12295,11 @@ function safeMessage(value, max = 300) {
12011
12295
  }
12012
12296
 
12013
12297
  // src/loop/index.ts
12014
- var import_crypto2 = __toESM(require("crypto"));
12298
+ var import_crypto3 = __toESM(require("crypto"));
12015
12299
  var LOOP_MAX_RECORDS = 500;
12016
12300
  function computeArgsHash(args) {
12017
12301
  const str = JSON.stringify(args ?? "");
12018
- return import_crypto2.default.createHash("sha256").update(str).digest("hex").slice(0, 16);
12302
+ return import_crypto3.default.createHash("sha256").update(str).digest("hex").slice(0, 16);
12019
12303
  }
12020
12304
  function evaluateLoopWindow(records, tool, args, threshold, windowMs, now) {
12021
12305
  const hash2 = computeArgsHash(args);
@@ -12310,88 +12594,6 @@ var FILE_TOOLS = /* @__PURE__ */ new Set([
12310
12594
  "list_files"
12311
12595
  ]);
12312
12596
 
12313
- // src/scan/pii.ts
12314
- var PII_EMAIL_RE = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/;
12315
- var PII_SSN_RE = /\b\d{3}-\d{2}-\d{4}\b/;
12316
- var PII_PHONE_RE = /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/;
12317
- var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|6\d{3})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/;
12318
- var PII_CC15_RE = /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/;
12319
- var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
12320
- function hasValidCard(text) {
12321
- for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
12322
- const re = new RegExp(base2.source, "g");
12323
- let m;
12324
- while ((m = re.exec(text)) !== null) {
12325
- const digits = m[0].replace(/\D/g, "");
12326
- if (!isDecimalFraction(text, m.index, digits.length === m[0].length)) {
12327
- if (validateLuhn(digits)) return true;
12328
- }
12329
- re.lastIndex = m.index + 1;
12330
- }
12331
- }
12332
- return false;
12333
- }
12334
- function isDecimalFraction(text, index, unseparated) {
12335
- if (!unseparated || text[index - 1] !== ".") return false;
12336
- const before = text.charCodeAt(index - 2);
12337
- return before >= 48 && before <= 57;
12338
- }
12339
- function hasValidIban(text) {
12340
- const re = new RegExp(PII_IBAN_RE.source, "g");
12341
- let m;
12342
- while ((m = re.exec(text)) !== null) {
12343
- if (validateIban(m[0])) return true;
12344
- re.lastIndex = m.index + 1;
12345
- }
12346
- return false;
12347
- }
12348
- function detectPii(text) {
12349
- const found = /* @__PURE__ */ new Set();
12350
- if (/@/.test(text) && PII_EMAIL_RE.test(text)) found.add("Email");
12351
- if (/-/.test(text) && PII_SSN_RE.test(text)) found.add("SSN");
12352
- if (PII_PHONE_RE.test(text)) found.add("Phone");
12353
- if (hasValidCard(text)) found.add("Credit Card");
12354
- if (hasValidIban(text)) found.add("IBAN");
12355
- return [...found];
12356
- }
12357
- var REALTIME_PII_PATTERNS = ["SSN", "Credit Card", "IBAN"];
12358
- var MAX_PII_SCAN_BYTES = 1e5;
12359
- function* stringLeaves(v, depth = 0) {
12360
- if (depth > 6) return;
12361
- if (typeof v === "string") {
12362
- if (v.length > 0) yield v;
12363
- return;
12364
- }
12365
- if (typeof v === "number") {
12366
- if (Number.isFinite(v)) yield String(v);
12367
- return;
12368
- }
12369
- if (!v || typeof v !== "object") return;
12370
- if (Array.isArray(v)) {
12371
- for (const x of v) yield* stringLeaves(x, depth + 1);
12372
- return;
12373
- }
12374
- for (const x of Object.values(v)) yield* stringLeaves(x, depth + 1);
12375
- }
12376
- function detectArgsPii(args) {
12377
- if (args === null || args === void 0) return [];
12378
- const found = /* @__PURE__ */ new Set();
12379
- let budget = MAX_PII_SCAN_BYTES;
12380
- try {
12381
- for (const leaf of stringLeaves(args)) {
12382
- if (budget <= 0) break;
12383
- const t = leaf.length > budget ? leaf.slice(0, budget) : leaf;
12384
- budget -= t.length;
12385
- for (const p of detectPii(t)) {
12386
- if (REALTIME_PII_PATTERNS.includes(p)) found.add(p);
12387
- }
12388
- }
12389
- } catch {
12390
- return [];
12391
- }
12392
- return [...found];
12393
- }
12394
-
12395
12597
  // src/dlp/canary.ts
12396
12598
  var CANARY_MIN_LENGTH = 16;
12397
12599
  var MAX_TEXT = 1e5;
@@ -12563,8 +12765,8 @@ function matchCanaryArgs(args, values) {
12563
12765
 
12564
12766
  // src/scan/canonical.ts
12565
12767
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
12566
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v26";
12567
- var CANONICAL_EXTRACTOR_HASH = "dec8c65145686360";
12768
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
12769
+ var CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
12568
12770
  var DEDUPE_PREVIEW_LEN = 120;
12569
12771
  function extractCanonicalFindings(call, ctx) {
12570
12772
  const out = [];
@@ -13016,6 +13218,7 @@ var ENGINE_VERSION = "1.4.0";
13016
13218
  detectDangerousShellExec,
13017
13219
  detectInlineExec,
13018
13220
  detectPii,
13221
+ entryDisplay,
13019
13222
  evaluateEgress,
13020
13223
  evaluateLoopWindow,
13021
13224
  evaluatePolicy,
@@ -13039,6 +13242,7 @@ var ENGINE_VERSION = "1.4.0";
13039
13242
  getCompiledRegex,
13040
13243
  getNestedValue,
13041
13244
  gitRepoPath,
13245
+ hashDestination,
13042
13246
  hostMatches,
13043
13247
  incompleteFileVerdict,
13044
13248
  inspectArgumentSecrets,
@@ -13047,12 +13251,14 @@ var ENGINE_VERSION = "1.4.0";
13047
13251
  isAgentInstructionPath,
13048
13252
  isBashTool,
13049
13253
  isDestructiveToolName,
13254
+ isHashedEntry,
13050
13255
  isIgnoredTool,
13051
13256
  isInside,
13052
13257
  isKnobGoverned,
13053
13258
  isLegacySystemPath,
13054
13259
  isLockedCheck,
13055
13260
  isLoopbackHost,
13261
+ isMaskedKind,
13056
13262
  isPasswordHashPath,
13057
13263
  isPrivateHost,
13058
13264
  isProtectedHomePath,
@@ -13060,16 +13266,24 @@ var ENGINE_VERSION = "1.4.0";
13060
13266
  isShieldVerdict,
13061
13267
  isStrictGatedTier,
13062
13268
  isVerdict,
13269
+ maskDestination,
13270
+ maskPersonalData,
13271
+ maskPersonalValue,
13063
13272
  matchCanary,
13064
13273
  matchCanaryArgs,
13065
13274
  matchSensitivePath,
13066
13275
  matchesPattern,
13276
+ matchesTrustedEntry,
13277
+ matchesTrustedList,
13067
13278
  narrativeRuleLabel,
13068
13279
  normalizeCommandForPolicy,
13280
+ normalizeDestination,
13069
13281
  normalizeFilePath,
13070
13282
  normalizeForScan,
13071
13283
  normalizeIpLiteral,
13072
13284
  normalizePyPiName,
13285
+ normalizeRecipient,
13286
+ normalizeTrustedEntry,
13073
13287
  parseAllSshHostsFromCommand,
13074
13288
  parseDestHost,
13075
13289
  patternShapeOf,
@@ -13103,6 +13317,7 @@ var ENGINE_VERSION = "1.4.0";
13103
13317
  toScanFinding,
13104
13318
  toolMatchesRule,
13105
13319
  truncateBlastPath,
13320
+ trustedEntryOf,
13106
13321
  tuningFromLegacyPolicy,
13107
13322
  tuningToLegacyPolicy,
13108
13323
  unwrapCommandHead,
package/dist/index.mjs CHANGED
@@ -11322,6 +11322,277 @@ function isDestructiveToolName(bareTool) {
11322
11322
  return DESTRUCTIVE_VERB_RE.test(bareTool);
11323
11323
  }
11324
11324
 
11325
+ // src/exposure/mask.ts
11326
+ import { createHash as createHash3 } from "crypto";
11327
+
11328
+ // src/scan/pii.ts
11329
+ var PII_EMAIL_RE = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/;
11330
+ var PII_SSN_RE = /\b\d{3}-\d{2}-\d{4}\b/;
11331
+ var PII_PHONE_RE = /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/;
11332
+ var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|6\d{3})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/;
11333
+ var PII_CC15_RE = /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/;
11334
+ var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
11335
+ function* validCardRuns(text, base2, exemptFractions = true) {
11336
+ const re = new RegExp(base2.source, "g");
11337
+ let m;
11338
+ while ((m = re.exec(text)) !== null) {
11339
+ const digits = m[0].replace(/\D/g, "");
11340
+ const fraction = exemptFractions && isDecimalFraction(text, m.index, digits.length === m[0].length);
11341
+ if (!fraction && validateLuhn(digits)) {
11342
+ yield { index: m.index, length: m[0].length, digits };
11343
+ } else {
11344
+ re.lastIndex = m.index + 1;
11345
+ }
11346
+ }
11347
+ }
11348
+ function hasValidCard(text) {
11349
+ for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
11350
+ if (!validCardRuns(text, base2).next().done) return true;
11351
+ }
11352
+ return false;
11353
+ }
11354
+ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
11355
+ let out = text;
11356
+ for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
11357
+ let res = "";
11358
+ let last = 0;
11359
+ for (const run of validCardRuns(out, base2, exemptFractions)) {
11360
+ res += out.slice(last, run.index) + replace(run.digits);
11361
+ last = run.index + run.length;
11362
+ }
11363
+ out = res + out.slice(last);
11364
+ }
11365
+ return out;
11366
+ }
11367
+ var NUMBER_LEAD_RE = /[\s:=;([{"'+-]/;
11368
+ function isDecimalFraction(text, index, unseparated) {
11369
+ if (!unseparated) return false;
11370
+ const sep = text[index - 1];
11371
+ const a = text[index - 2];
11372
+ if (sep === ".") {
11373
+ if (a !== void 0 && a >= "0" && a <= "9") return true;
11374
+ return a === void 0 || NUMBER_LEAD_RE.test(a);
11375
+ }
11376
+ if (sep === "," && a === "0") {
11377
+ const b = text[index - 3];
11378
+ return b === void 0 || NUMBER_LEAD_RE.test(b);
11379
+ }
11380
+ return false;
11381
+ }
11382
+ function hasValidIban(text) {
11383
+ const re = new RegExp(PII_IBAN_RE.source, "g");
11384
+ let m;
11385
+ while ((m = re.exec(text)) !== null) {
11386
+ if (validateIban(m[0])) return true;
11387
+ re.lastIndex = m.index + 1;
11388
+ }
11389
+ return false;
11390
+ }
11391
+ function detectPii(text) {
11392
+ const found = /* @__PURE__ */ new Set();
11393
+ if (/@/.test(text) && PII_EMAIL_RE.test(text)) found.add("Email");
11394
+ if (/-/.test(text) && PII_SSN_RE.test(text)) found.add("SSN");
11395
+ if (PII_PHONE_RE.test(text)) found.add("Phone");
11396
+ if (hasValidCard(text)) found.add("Credit Card");
11397
+ if (hasValidIban(text)) found.add("IBAN");
11398
+ return [...found];
11399
+ }
11400
+ var REALTIME_PII_PATTERNS = ["SSN", "Credit Card", "IBAN"];
11401
+ var MAX_PII_SCAN_BYTES = 1e5;
11402
+ function* stringLeaves(v, depth = 0) {
11403
+ if (depth > 6) return;
11404
+ if (typeof v === "string") {
11405
+ if (v.length > 0) yield v;
11406
+ return;
11407
+ }
11408
+ if (typeof v === "number") {
11409
+ if (Number.isFinite(v)) yield String(v);
11410
+ return;
11411
+ }
11412
+ if (!v || typeof v !== "object") return;
11413
+ if (Array.isArray(v)) {
11414
+ for (const x of v) yield* stringLeaves(x, depth + 1);
11415
+ return;
11416
+ }
11417
+ for (const x of Object.values(v)) yield* stringLeaves(x, depth + 1);
11418
+ }
11419
+ function detectArgsPii(args) {
11420
+ if (args === null || args === void 0) return [];
11421
+ const found = /* @__PURE__ */ new Set();
11422
+ let budget = MAX_PII_SCAN_BYTES;
11423
+ try {
11424
+ for (const leaf of stringLeaves(args)) {
11425
+ if (budget <= 0) break;
11426
+ const t = leaf.length > budget ? leaf.slice(0, budget) : leaf;
11427
+ budget -= t.length;
11428
+ for (const p of detectPii(t)) {
11429
+ if (REALTIME_PII_PATTERNS.includes(p)) found.add(p);
11430
+ }
11431
+ }
11432
+ } catch {
11433
+ return [];
11434
+ }
11435
+ return [...found];
11436
+ }
11437
+
11438
+ // src/exposure/mask.ts
11439
+ var MASKED_KINDS = /* @__PURE__ */ new Set(["email", "iban", "account"]);
11440
+ var ENTRY_RE = /^(email|iban|account):([^#\s]{1,200}(?: [^#\s]{1,40}){0,4})#sha256:([0-9a-f]{64})$/;
11441
+ function split(dest) {
11442
+ const i = dest.indexOf(":");
11443
+ if (i <= 0) return null;
11444
+ return { kind: dest.slice(0, i).toLowerCase(), value: dest.slice(i + 1) };
11445
+ }
11446
+ function normalizeDestination(dest) {
11447
+ const p = split(dest.trim());
11448
+ if (!p) return dest.trim();
11449
+ if (p.kind === "iban" || p.kind === "account")
11450
+ return `${p.kind}:${p.value.replace(/\s+/g, "").toUpperCase()}`;
11451
+ return `${p.kind}:${p.value.toLowerCase()}`;
11452
+ }
11453
+ function maskEmailValue(address) {
11454
+ const at = address.lastIndexOf("@");
11455
+ if (at <= 0) return "***";
11456
+ return `${address[0]}***@${address.slice(at + 1)}`;
11457
+ }
11458
+ function maskDestination(dest) {
11459
+ const n = normalizeDestination(dest);
11460
+ const p = split(n);
11461
+ if (!p || !MASKED_KINDS.has(p.kind)) return n;
11462
+ if (p.kind === "iban") return `iban:${p.value.slice(0, 4)} **** **** ${p.value.slice(-4)}`;
11463
+ if (p.kind === "account") return `account:****${p.value.slice(-4)}`;
11464
+ return `email:${maskEmailValue(p.value)}`;
11465
+ }
11466
+ function isMaskedKind(dest) {
11467
+ const p = split(dest);
11468
+ return !!p && MASKED_KINDS.has(p.kind);
11469
+ }
11470
+ function hashDestination(dest) {
11471
+ return createHash3("sha256").update(normalizeDestination(dest), "utf8").digest("hex");
11472
+ }
11473
+ function isHashedEntry(entry) {
11474
+ return ENTRY_RE.test(entry);
11475
+ }
11476
+ function trustedEntryOf(dest) {
11477
+ const n = normalizeDestination(dest);
11478
+ if (!isMaskedKind(n)) return n;
11479
+ return `${maskDestination(n)}#sha256:${hashDestination(n)}`;
11480
+ }
11481
+ function matchesTrustedEntry(dest, entry) {
11482
+ const m = ENTRY_RE.exec(entry);
11483
+ if (m) return hashDestination(dest) === m[3];
11484
+ return normalizeDestination(dest) === normalizeDestination(entry);
11485
+ }
11486
+ function matchesTrustedList(dest, entries) {
11487
+ if (entries.length === 0) return false;
11488
+ const plain = normalizeDestination(dest);
11489
+ let hash2;
11490
+ for (const entry of entries) {
11491
+ const m = ENTRY_RE.exec(entry);
11492
+ if (m) {
11493
+ hash2 ??= hashDestination(dest);
11494
+ if (hash2 === m[3]) return true;
11495
+ } else if (plain === normalizeDestination(entry)) return true;
11496
+ }
11497
+ return false;
11498
+ }
11499
+ function normalizeRecipient(raw) {
11500
+ if (typeof raw !== "string") return null;
11501
+ const v = raw.trim();
11502
+ if (!v || v.length > 512) return null;
11503
+ const acct = /^account:([A-Za-z0-9 ]{8,40})$/i.exec(v);
11504
+ if (acct) {
11505
+ const n = acct[1].replace(/\s+/g, "").toUpperCase();
11506
+ return n.length >= 8 && n.length <= 34 ? `account:${n}` : null;
11507
+ }
11508
+ if (/^(email|host|iban):/i.test(v)) {
11509
+ const i = v.indexOf(":");
11510
+ const kind = v.slice(0, i).toLowerCase();
11511
+ const inner = normalizeRecipient(v.slice(i + 1));
11512
+ return inner && inner.startsWith(`${kind}:`) ? inner : null;
11513
+ }
11514
+ const found = extractArgDestinations({ to: v });
11515
+ return found.length === 1 ? found[0] : null;
11516
+ }
11517
+ function normalizeTrustedEntry(raw) {
11518
+ if (typeof raw !== "string") return null;
11519
+ const v = raw.trim().replace(/#sha256:([0-9A-Fa-f]{64})$/, (_m, h) => `#sha256:${h.toLowerCase()}`);
11520
+ if (v.includes("#")) return isHashedEntry(v) ? v : null;
11521
+ const full = normalizeRecipient(v);
11522
+ return full === null ? null : trustedEntryOf(full);
11523
+ }
11524
+ function entryDisplay(entry) {
11525
+ const i = entry.indexOf("#sha256:");
11526
+ return i > 0 ? entry.slice(0, i) : entry;
11527
+ }
11528
+ var IBAN_TEXT_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/gi;
11529
+ var EMAIL_TEXT_RE = /[\p{L}\p{N}._%+-]+@[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?(?:\.[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?)*\.\p{L}{2,}/gu;
11530
+ var ACCOUNT_KEY_RE = /("(?:iban|account|account_number|accountNumber)"\s*:\s*")([A-Za-z0-9 .-]{6,40})(")/g;
11531
+ var ACCOUNT_VALUE_RE = /"([A-Z]{2}\d{2}[A-Z0-9]{11,30})"/g;
11532
+ function maskPersonalData(text) {
11533
+ return maskText(text, false);
11534
+ }
11535
+ function maskText(text, exemptFractions) {
11536
+ if (!text) return text;
11537
+ try {
11538
+ let out = text;
11539
+ out = out.replace(IBAN_TEXT_RE, (m) => {
11540
+ const v = m.replace(/[ -]/g, "").toUpperCase();
11541
+ return validateIban(v) ? `${v.slice(0, 4)} **** **** ${v.slice(-4)}` : m;
11542
+ });
11543
+ out = replaceValidCards(out, (digits) => `**** **** **** ${digits.slice(-4)}`, {
11544
+ exemptFractions
11545
+ });
11546
+ out = out.replace(
11547
+ ACCOUNT_VALUE_RE,
11548
+ (m, v) => IBAN_LENGTH[v.slice(0, 2).toUpperCase()] === v.length ? `"****${v.slice(-4)}"` : m
11549
+ );
11550
+ out = out.replace(ACCOUNT_KEY_RE, (m, a, v, b) => {
11551
+ const compact = v.replace(/[ .-]/g, "");
11552
+ const digits = compact.replace(/\D/g, "").length;
11553
+ return digits >= 6 && digits * 2 >= compact.length ? `${a}****${compact.slice(-4)}${b}` : m;
11554
+ });
11555
+ if (out.includes("@")) out = out.replace(EMAIL_TEXT_RE, (m) => maskEmailValue(m));
11556
+ return out;
11557
+ } catch {
11558
+ return text;
11559
+ }
11560
+ }
11561
+ var MAX_MASK_DEPTH = 64;
11562
+ function maskPersonalValue(value) {
11563
+ return maskLeaf(value, "", 0);
11564
+ }
11565
+ function maskLeaf(value, key, depth) {
11566
+ if (depth > MAX_MASK_DEPTH) return "[REDACTED]";
11567
+ if (typeof value === "string") {
11568
+ try {
11569
+ const json = `{${JSON.stringify(key)}:${JSON.stringify(maskPersonalData(value))}}`;
11570
+ return Object.values(JSON.parse(maskPersonalData(json)))[0];
11571
+ } catch {
11572
+ return "[REDACTED]";
11573
+ }
11574
+ }
11575
+ if (typeof value === "number") {
11576
+ const text = String(value);
11577
+ const masked = maskText(text, true);
11578
+ return masked === text ? value : masked;
11579
+ }
11580
+ if (Array.isArray(value)) return value.map((v) => maskLeaf(v, key, depth + 1));
11581
+ if (value && typeof value === "object") {
11582
+ const used = /* @__PURE__ */ new Set();
11583
+ return Object.fromEntries(
11584
+ Object.entries(value).map(([k, v]) => {
11585
+ const base2 = maskPersonalData(k);
11586
+ let name = base2;
11587
+ for (let n = 2; used.has(name); n++) name = `${base2}#${n}`;
11588
+ used.add(name);
11589
+ return [name, maskLeaf(v, k, depth + 1)];
11590
+ })
11591
+ );
11592
+ }
11593
+ return value;
11594
+ }
11595
+
11325
11596
  // src/exposure/shell.ts
11326
11597
  import mvdanSh4 from "mvdan-sh";
11327
11598
  var { syntax: syntax4 } = mvdanSh4;
@@ -12101,88 +12372,6 @@ var FILE_TOOLS = /* @__PURE__ */ new Set([
12101
12372
  "list_files"
12102
12373
  ]);
12103
12374
 
12104
- // src/scan/pii.ts
12105
- var PII_EMAIL_RE = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/;
12106
- var PII_SSN_RE = /\b\d{3}-\d{2}-\d{4}\b/;
12107
- var PII_PHONE_RE = /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/;
12108
- var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|6\d{3})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/;
12109
- var PII_CC15_RE = /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/;
12110
- var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
12111
- function hasValidCard(text) {
12112
- for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
12113
- const re = new RegExp(base2.source, "g");
12114
- let m;
12115
- while ((m = re.exec(text)) !== null) {
12116
- const digits = m[0].replace(/\D/g, "");
12117
- if (!isDecimalFraction(text, m.index, digits.length === m[0].length)) {
12118
- if (validateLuhn(digits)) return true;
12119
- }
12120
- re.lastIndex = m.index + 1;
12121
- }
12122
- }
12123
- return false;
12124
- }
12125
- function isDecimalFraction(text, index, unseparated) {
12126
- if (!unseparated || text[index - 1] !== ".") return false;
12127
- const before = text.charCodeAt(index - 2);
12128
- return before >= 48 && before <= 57;
12129
- }
12130
- function hasValidIban(text) {
12131
- const re = new RegExp(PII_IBAN_RE.source, "g");
12132
- let m;
12133
- while ((m = re.exec(text)) !== null) {
12134
- if (validateIban(m[0])) return true;
12135
- re.lastIndex = m.index + 1;
12136
- }
12137
- return false;
12138
- }
12139
- function detectPii(text) {
12140
- const found = /* @__PURE__ */ new Set();
12141
- if (/@/.test(text) && PII_EMAIL_RE.test(text)) found.add("Email");
12142
- if (/-/.test(text) && PII_SSN_RE.test(text)) found.add("SSN");
12143
- if (PII_PHONE_RE.test(text)) found.add("Phone");
12144
- if (hasValidCard(text)) found.add("Credit Card");
12145
- if (hasValidIban(text)) found.add("IBAN");
12146
- return [...found];
12147
- }
12148
- var REALTIME_PII_PATTERNS = ["SSN", "Credit Card", "IBAN"];
12149
- var MAX_PII_SCAN_BYTES = 1e5;
12150
- function* stringLeaves(v, depth = 0) {
12151
- if (depth > 6) return;
12152
- if (typeof v === "string") {
12153
- if (v.length > 0) yield v;
12154
- return;
12155
- }
12156
- if (typeof v === "number") {
12157
- if (Number.isFinite(v)) yield String(v);
12158
- return;
12159
- }
12160
- if (!v || typeof v !== "object") return;
12161
- if (Array.isArray(v)) {
12162
- for (const x of v) yield* stringLeaves(x, depth + 1);
12163
- return;
12164
- }
12165
- for (const x of Object.values(v)) yield* stringLeaves(x, depth + 1);
12166
- }
12167
- function detectArgsPii(args) {
12168
- if (args === null || args === void 0) return [];
12169
- const found = /* @__PURE__ */ new Set();
12170
- let budget = MAX_PII_SCAN_BYTES;
12171
- try {
12172
- for (const leaf of stringLeaves(args)) {
12173
- if (budget <= 0) break;
12174
- const t = leaf.length > budget ? leaf.slice(0, budget) : leaf;
12175
- budget -= t.length;
12176
- for (const p of detectPii(t)) {
12177
- if (REALTIME_PII_PATTERNS.includes(p)) found.add(p);
12178
- }
12179
- }
12180
- } catch {
12181
- return [];
12182
- }
12183
- return [...found];
12184
- }
12185
-
12186
12375
  // src/dlp/canary.ts
12187
12376
  var CANARY_MIN_LENGTH = 16;
12188
12377
  var MAX_TEXT = 1e5;
@@ -12354,8 +12543,8 @@ function matchCanaryArgs(args, values) {
12354
12543
 
12355
12544
  // src/scan/canonical.ts
12356
12545
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
12357
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v26";
12358
- var CANONICAL_EXTRACTOR_HASH = "dec8c65145686360";
12546
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
12547
+ var CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
12359
12548
  var DEDUPE_PREVIEW_LEN = 120;
12360
12549
  function extractCanonicalFindings(call, ctx) {
12361
12550
  const out = [];
@@ -12806,6 +12995,7 @@ export {
12806
12995
  detectDangerousShellExec,
12807
12996
  detectInlineExec,
12808
12997
  detectPii,
12998
+ entryDisplay,
12809
12999
  evaluateEgress,
12810
13000
  evaluateLoopWindow,
12811
13001
  evaluatePolicy,
@@ -12829,6 +13019,7 @@ export {
12829
13019
  getCompiledRegex,
12830
13020
  getNestedValue,
12831
13021
  gitRepoPath,
13022
+ hashDestination,
12832
13023
  hostMatches,
12833
13024
  incompleteFileVerdict,
12834
13025
  inspectArgumentSecrets,
@@ -12837,12 +13028,14 @@ export {
12837
13028
  isAgentInstructionPath,
12838
13029
  isBashTool,
12839
13030
  isDestructiveToolName,
13031
+ isHashedEntry,
12840
13032
  isIgnoredTool,
12841
13033
  isInside,
12842
13034
  isKnobGoverned,
12843
13035
  isLegacySystemPath,
12844
13036
  isLockedCheck,
12845
13037
  isLoopbackHost,
13038
+ isMaskedKind,
12846
13039
  isPasswordHashPath,
12847
13040
  isPrivateHost,
12848
13041
  isProtectedHomePath,
@@ -12850,16 +13043,24 @@ export {
12850
13043
  isShieldVerdict,
12851
13044
  isStrictGatedTier,
12852
13045
  isVerdict,
13046
+ maskDestination,
13047
+ maskPersonalData,
13048
+ maskPersonalValue,
12853
13049
  matchCanary,
12854
13050
  matchCanaryArgs,
12855
13051
  matchSensitivePath2 as matchSensitivePath,
12856
13052
  matchesPattern,
13053
+ matchesTrustedEntry,
13054
+ matchesTrustedList,
12857
13055
  narrativeRuleLabel,
12858
13056
  normalizeCommandForPolicy,
13057
+ normalizeDestination,
12859
13058
  normalizeFilePath,
12860
13059
  normalizeForScan,
12861
13060
  normalizeIpLiteral,
12862
13061
  normalizePyPiName,
13062
+ normalizeRecipient,
13063
+ normalizeTrustedEntry,
12863
13064
  parseAllSshHostsFromCommand,
12864
13065
  parseDestHost,
12865
13066
  patternShapeOf,
@@ -12893,6 +13094,7 @@ export {
12893
13094
  toScanFinding,
12894
13095
  toolMatchesRule,
12895
13096
  truncateBlastPath,
13097
+ trustedEntryOf,
12896
13098
  tuningFromLegacyPolicy,
12897
13099
  tuningToLegacyPolicy,
12898
13100
  unwrapCommandHead,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/policy-engine",
3
- "version": "2.33.0",
3
+ "version": "2.33.2",
4
4
  "description": "Shared policy evaluation engine for node9 — DLP, smart rules, AST shell parsing, shields, loop detection. Pure functions, no I/O. Used by both node9-proxy and the node9 SaaS firewall.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://node9.ai",