google-gemini/gemini-cli · critical
Security violation: Null byte detected in path.
Error message
Security violation: Null byte detected in path.
What it means
validateWorkspacePath() rejects any input containing a null byte (\0). Null bytes can truncate path strings at the C-level syscall boundary in some environments, enabling POISON NULL BYTE attacks that bypass security checks and access unintended files.
Source
Thrown at packages/a2a-server/src/utils/path_utils.ts:29
/**
* Validates a workspace path to prevent path traversal attacks.
*
* @param workspacePath The path to validate.
* @param allowedRoot The root directory the path must be within. Defaults to CWD.
* @returns The resolved, safe path.
* @throws An error if the path is invalid or outside the allowed root.
*/
export async function validateWorkspacePath(
workspacePath?: string,
allowedRoot: string = process.cwd(),
): Promise<string> {
const trimmedPath = workspacePath?.trim();
if (!trimmedPath) {
return resolveToRealPath(allowedRoot);
}
if (trimmedPath.includes('\0')) {
throw new Error('Security violation: Null byte detected in path.');
}
try {
const canonicalAllowedRoot = resolveToRealPath(allowedRoot);
const resolvedWorkspacePath = path.resolve(
canonicalAllowedRoot,
trimmedPath,
);
const canonicalWorkspacePath = resolveToRealPath(resolvedWorkspacePath);
// Check if the resolved path is within the allowed root directory
if (
canonicalWorkspacePath !== canonicalAllowedRoot &&
!isSubpath(canonicalAllowedRoot, canonicalWorkspacePath)
) {
throw new Error(
`Security violation: The path "${trimmedPath}" is outside the allowed root directory.`,
);View on GitHub (pinned to 5024443c72)
Solutions
- Sanitize all user-supplied path input to strip or reject control characters before calling validateWorkspacePath.
- Validate at the API boundary that paths contain only expected filename characters.
- Treat the error as a security alert and log the source of the malicious input.
Example fix
// before
const safePath = await validateWorkspacePath(userInput); // throws if userInput has \0
// after
if (userInput.includes('\0')) {
throw new TypeError('Invalid characters in path');
}
const safePath = await validateWorkspacePath(userInput); Defensive patterns
Strategy: validation
Validate before calling
function isSafePath(input: string): boolean {
return !input.includes('\0');
}
// Before calling validateWorkspacePath:
if (!isSafePath(userInput)) {
throw new TypeError('Path contains illegal null byte characters.');
}
const safe = await validateWorkspacePath(userInput); Type guard
function isNullByteFree(value: string): boolean {
return !value.includes('\0');
} Prevention
- Sanitize all user-supplied or external path input at the API boundary to reject control characters.
- Treat null-byte detection as a security incident — log the request source.
- Never pass raw binary data or untrusted strings as path parameters.
When it happens
Trigger: Calling validateWorkspacePath(path) where path includes '\0' anywhere — e.g., 'safe\0/../../etc/passwd'. This is a classic injection vector or corrupted input from untrusted sources.
Common situations: Untrusted user input passed as a workspace path without sanitization; copy-paste artifacts containing embedded control characters; test fixtures with raw null bytes; binary data mistakenly interpreted as a string path.
Related errors
- Invalid taskId: ${taskId}
- Security violation: The path "${trimmedPath}" is outside the
- Invalid path: Directory traversal not allowed.
- Invalid skill name: Path traversal detected.
- Path validation failed: ${pathError}
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/0df031a10332a64d.
Report an issue: GitHub.