Skip to content

Commit

Permalink
chore: Properly sanitize extension names on all interactions with add…
Browse files Browse the repository at this point in the history
…/remove (#737)
  • Loading branch information
alexhancock authored Jan 24, 2025
1 parent b447902 commit d6620ab
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ui/desktop/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const BUILT_IN_EXTENSIONS = [
},
];

function sanitizeName(name: string) {
return name.toLowerCase().replace(/-/g, '').replace(/_/g, '').replace(/\s/g, '');
}

export async function addExtension(
extension: FullExtensionConfig,
silent: boolean = false
Expand All @@ -97,16 +101,16 @@ export async function addExtension(
const config = {
type: extension.type,
...(extension.type === 'stdio' && {
name: extension.name,
name: sanitizeName(extension.name),
cmd: await replaceWithShims(extension.cmd),
args: extension.args || [],
}),
...(extension.type === 'sse' && {
name: extension.name,
name: sanitizeName(extension.name),
uri: extension.uri,
}),
...(extension.type === 'builtin' && {
name: extension.name.toLowerCase().replace(/-/g, '').replace(/\s/g, '_'),
name: sanitizeName(extension.name),
}),
env_keys: extension.env_keys,
};
Expand Down Expand Up @@ -149,7 +153,7 @@ export async function removeExtension(name: string): Promise<Response> {
'Content-Type': 'application/json',
'X-Secret-Key': getSecretKey(),
},
body: JSON.stringify(name),
body: JSON.stringify(sanitizeName(name)),
});

const data = await response.json();
Expand Down

0 comments on commit d6620ab

Please sign in to comment.