UNPKG

@aptos-labs/ts-sdk

Version:
39 lines 1.95 kB
/** * Validates that a CLI argument does not contain shell metacharacters that * could be interpreted by the shell when passed via `spawn(..., { shell: true })`. * * @throws Error if `arg` contains any unsafe shell character. */ export declare function assertSafeCliArg(arg: string): void; /** * Validates every element of an args array. See {@link assertSafeCliArg}. */ export declare function assertSafeCliArgs(args: ReadonlyArray<string>): void; /** * Validates a single CLI argument and returns a copy with any shell * metacharacters stripped out. * * {@link assertSafeCliArg} already rejects every shell metacharacter, so the * scrubbing chain below is a runtime no-op for any argument that passes * validation. We keep it as defense-in-depth and, importantly, so that static * analysis (e.g. CodeQL's "Unsafe shell command constructed from library * input" query) can see that the value flowing into `spawn(..., { shell: true })` * on Windows has been stripped of shell metacharacters. CodeQL only recognizes * a sequence of `String.prototype.replace` calls that covers every shell * metacharacter as a sanitizer barrier; a `RegExp.test`-based guard in a * separate function is not enough to break the tracked data flow. * * The chain strips every character that {@link UNSAFE_SHELL_CHARS}/ * {@link assertSafeCliArg} reject, so the scrub is a complete superset of the * validation blocklist rather than only the subset CodeQL requires. * * @returns the validated argument with shell metacharacters removed. * @throws Error if `arg` contains any unsafe shell character. */ export declare function sanitizeCliArg(arg: string): string; /** * Validates and scrubs every element of an args array, returning the sanitized * array that should be passed to `spawn`. See {@link sanitizeCliArg}. */ export declare function sanitizeCliArgs(args: ReadonlyArray<string>): string[]; //# sourceMappingURL=spawnArgs.d.ts.map