Sanitize command names and descriptions (#17228)

This commit is contained in:
Emily Hedlund
2026-01-22 11:41:51 -05:00
committed by GitHub
parent 048c30513e
commit d956c5b221
6 changed files with 134 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ import {
ShellProcessor,
} from './prompt-processors/shellProcessor.js';
import { AtFileProcessor } from './prompt-processors/atFileProcessor.js';
import { sanitizeForListDisplay } from '../ui/utils/textUtils.js';
interface CommandDirectory {
path: string;
@@ -230,15 +231,25 @@ export class FileCommandLoader implements ICommandLoader {
);
const baseCommandName = relativePath
.split(path.sep)
// Sanitize each path segment to prevent ambiguity. Since ':' is our
// namespace separator, we replace any literal colons in filenames
// with underscores to avoid naming conflicts.
.map((segment) => segment.replaceAll(':', '_'))
// Sanitize each path segment to prevent ambiguity, replacing non-allowlisted characters with underscores.
// Since ':' is our namespace separator, this ensures that colons do not cause naming conflicts.
.map((segment) => {
let sanitized = segment.replace(/[^a-zA-Z0-9_\-.]/g, '_');
// Truncate excessively long segments to prevent UI overflow
if (sanitized.length > 50) {
sanitized = sanitized.substring(0, 47) + '...';
}
return sanitized;
})
.join(':');
// Add extension name tag for extension commands
const defaultDescription = `Custom command from ${path.basename(filePath)}`;
let description = validDef.description || defaultDescription;
description = sanitizeForListDisplay(description, 100);
if (extensionName) {
description = `[${extensionName}] ${description}`;
}