Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Address Veria comment

Carlos Monastyrski3d1fa87fac38
diff --git a/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.test.ts b/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.test.ts
index a11f7bb5c9..da43a6cdc5 100644
--- a/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.test.ts
+++ b/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.test.ts
@@ -1,9 +1,11 @@
import { CodeSigningScopeField } from "./code-signing-policy-enums";
import {
+ buildObservedSigningContext,
commandsMatch,
getCodeSigningScopeMismatches,
isSameRequestedSigningWindow,
- normalizeCodeSigningScope
+ normalizeCodeSigningScope,
+ redactCommandCredentials
} from "./code-signing-policy-fns";
const DIGEST = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9";
@@ -266,3 +268,42 @@ describe("isSameRequestedSigningWindow", () => {
expect(isSameRequestedSigningWindow(HUMAN, windowed, {})).toBe(false);
});
});
+
+describe("redactCommandCredentials", () => {
+ test.each([
+ ["custom-signer --api-token hunter2 --in app.exe", "custom-signer --api-token hunter2 --in app.exe"],
+ ["jarsigner -storepass hunter2 app.jar", "jarsigner -storepass *** app.jar"],
+ ["jarsigner -keypass=hunter2 app.jar", "jarsigner -keypass=*** app.jar"],
+ ["signtool sign /p hunter2 app.exe", "signtool sign /p *** app.exe"],
+ ["msbuild /p:Password=hunter2 a.sln", "msbuild /p:Password=*** a.sln"],
+ ["gradle -Psigning.password=hunter2", "gradle -Psigning.password=***"],
+ ["java -Dsigning.keyPassword=hunter2 -jar x.jar", "java -Dsigning.keyPassword=*** -jar x.jar"],
+ ["make sign PASSWORD=hunter2", "make sign PASSWORD=***"],
+ ["tool --db-passwd=hunter2", "tool --db-passwd=***"],
+ ["tool -pass:hunter2", "tool -pass:***"],
+ // A suffix name has to behave the same whether the value is inline or the next token.
+ ["tool --cert-password hunter2", "tool --cert-password ***"],
+ ["tool --cert-password=hunter2", "tool --cert-password=***"],
+ ["openssl -passin pass:hunter2", "openssl -passin ***"],
+ ['jarsigner -storepass "two words" app.jar', "jarsigner -storepass *** app.jar"],
+ // A secret flag with no value must not swallow the following flag.
+ ["signtool sign /p /f cert.pfx", "signtool sign /p /f cert.pfx"],
+ // Already redacted input stays put, so a client-redacted command is untouched.
+ ["jarsigner -storepass *** app.jar", "jarsigner -storepass *** app.jar"]
+ ])("redacts %j", (input, expected) => {
+ expect(redactCommandCredentials(input)).toBe(expected);
+ });
+
+ test("is idempotent", () => {
+ const once = redactCommandCredentials("jarsigner -storepass hunter2 -keypass=s3cret app.jar");
+ expect(redactCommandCredentials(once)).toBe(once);
+ });
+
+ test("keeps a bound and an observed command comparable after redaction", () => {
+ const raw = "custom-signer --password hunter2 --in app.exe";
+ const bound = normalizeCodeSigningScope({ command: raw });
+ const observed = buildObservedSigningContext({ clientMetadata: { command: raw }, dataHash: "d" });
+ expect(getCodeSigningScopeMismatches(bound, observed)).toEqual([]);
+ expect(bound?.command).not.toContain("hunter2");
+ });
+});
diff --git a/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.ts b/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.ts
index 1178552906..befa03f50b 100644
--- a/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.ts
+++ b/backend/src/services/approval-policy/code-signing/code-signing-policy-fns.ts
@@ -3,6 +3,33 @@ import RE2 from "re2";
import { CodeSigningScopeField } from "./code-signing-policy-enums";
import { TCodeSigningScope } from "./code-signing-policy-types";
+const REDACTED_VALUE = "***";
+
+const SECRET_ARGUMENT_NAMES = "storepass|keypass|passphrase|password|passwd|passin|passout|pass|pin|pw|p";
+const SECRET_NAME_SUFFIXES = "password|passphrase|passwd";
+
+const INLINE_SECRET_RE = new RE2(
+ `((?:^|\\s)[-/]{0,2}[A-Za-z0-9._:-]*(?:${SECRET_NAME_SUFFIXES})\\s*=\\s*)("[^"]*"|\\S+)`,
+ "gi"
+);
+const INLINE_NAMED_SECRET_RE = new RE2(`((?:^|\\s)[-/]{1,2}(?:${SECRET_ARGUMENT_NAMES})\\s*=\\s*)("[^"]*"|\\S+)`, "gi");
+const SEPARATED_SECRET_RE = new RE2(
+ `((?:^|\\s)[-/]{1,2}(?:${SECRET_ARGUMENT_NAMES}|[A-Za-z0-9._:-]*(?:${SECRET_NAME_SUFFIXES}))[ \\t]+)("[^"]*"|[^-/\\s]\\S*)`,
+ "gi"
+);
+const COLON_SECRET_RE = new RE2(`((?:^|\\s)[-/]{1,2}(?:${SECRET_ARGUMENT_NAMES}):)("[^"]*"|[^=\\s]+)(\\s|$)`, "gi");
+
+/**
+ * Strips credential values out of a command line.
+ */
+export const redactCommandCredentials = (command: string): string => {
+ const withoutInlineSecrets = [INLINE_SECRET_RE, INLINE_NAMED_SECRET_RE, SEPARATED_SECRET_RE].reduce(
+ (redacted, pattern) => redacted.replace(pattern, `$1${REDACTED_VALUE}`),
+ command
+ );
+ return withoutInlineSecrets.replace(COLON_SECRET_RE, `$1${REDACTED_VALUE}$3`);
+};
+
export const normalizeCodeSigningScope = (scope: TCodeSigningScope | undefined): TCodeSigningScope | undefined => {
if (!scope) return undefined;
@@ -11,7 +38,7 @@ export const normalizeCodeSigningScope = (scope: TCodeSigningScope | undefined):
for (const field of Object.values(CodeSigningScopeField)) {
const value = scope[field]?.trim();
if (value) {
- declared[field] = value;
+ declared[field] = field === CodeSigningScopeField.Command ? redactCommandCredentials(value) : value;
hasAny = true;
}
}
@@ -44,7 +71,9 @@ export const buildObservedSigningContext = ({
ipAddress?: string;
dataHash: string;
}): TObservedSigningContext => ({
- [CodeSigningScopeField.Command]: clientMetadata?.command,
+ [CodeSigningScopeField.Command]: clientMetadata?.command
+ ? redactCommandCredentials(clientMetadata.command)
+ : clientMetadata?.command,
[CodeSigningScopeField.SigningApplication]: clientMetadata?.tool,
[CodeSigningScopeField.SigningApplicationHash]: clientMetadata?.signingApplicationHash,
[CodeSigningScopeField.Hostname]: clientMetadata?.hostname,
diff --git a/backend/src/services/signer/signer-service.ts b/backend/src/services/signer/signer-service.ts
index 0bd99d96d4..b6855e6837 100644
--- a/backend/src/services/signer/signer-service.ts
+++ b/backend/src/services/signer/signer-service.ts
@@ -52,6 +52,7 @@ import {
import {
buildObservedSigningContext,
getCodeSigningScopeMismatches,
+ redactCommandCredentials,
TObservedSigningContext
} from "../approval-policy/code-signing/code-signing-policy-fns";
import { TCodeSigningGrantAttributes } from "../approval-policy/code-signing/code-signing-policy-types";
@@ -1683,7 +1684,13 @@ export const signerServiceFactory = ({
dataHash
});
const operationClientMetadata =
- dto.clientMetadata || dto.ipAddress ? { ...dto.clientMetadata, sourceIp: dto.ipAddress } : null;
+ dto.clientMetadata || dto.ipAddress
+ ? {
+ ...dto.clientMetadata,
+ ...(dto.clientMetadata?.command ? { command: redactCommandCredentials(dto.clientMetadata.command) } : {}),
+ sourceIp: dto.ipAddress
+ }
+ : null;
let grantId: string | null = null;
let matchedGrantAttributes: TCodeSigningGrantAttributes | null = null;
diff --git a/docs/documentation/platform/pki/code-signing/approvals.mdx b/docs/documentation/platform/pki/code-signing/approvals.mdx
index 70ff66fa81..147ad1cda4 100644
--- a/docs/documentation/platform/pki/code-signing/approvals.mdx
+++ b/docs/documentation/platform/pki/code-signing/approvals.mdx
@@ -126,6 +126,8 @@ Two of these parameters are decided by Infisical rather than by the caller, whic
- **Data Digest** is computed from the payload submitted for signing. A caller can only obtain a signature over the bytes they actually sent, so an approval pinned to a digest cannot be turned into a signature over different content.
+A command is stored on the approval and on the signing operation, where approvers and auditors can read it. Infisical strips the values of credential arguments it recognises, and the [PKCS#11 module](/documentation/platform/pki/code-signing/pkcs11-module) and [Windows KSP](/documentation/platform/pki/code-signing/windows-ksp) strip them before sending too, but recognition is best-effort on both sides. Keep secrets off the command lines you sign with.
+
The remaining parameters (command, signing application, checksum, hostname, OS username) are reported by the signing client. With the [PKCS#11 module](/documentation/platform/pki/code-signing/pkcs11-module) they are captured from the real signing process, so they describe what is happening on well-behaved machines and give approvers useful context. Someone calling the [Sign API](/api-reference/endpoints/code-signing/signers/sign) directly, however, can report whatever values they like. Treat them as identification, not as a security boundary, and reach for **IP address** and **data digest** when you need a limit that holds regardless of how the caller behaves.
<Tip>