Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const paths = getEnvPaths()
*/
export function getEnvPaths(platform = process.platform): Paths {
const paths = envPaths("code-server", { suffix: "" })
const append = (p: string): string => path.join(p, "code-server")
const append = (p: string): string => path.join(p, "code-server") // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
switch (platform) {
case "darwin":
return {
Expand Down Expand Up @@ -432,10 +432,14 @@ export const open = async (address: URL | string): Promise<void> => {
if (url.hostname === "0.0.0.0") {
url.hostname = "localhost"
}
const protocol = url.protocol
if (protocol !== "http:" && protocol !== "https:") {
throw new Error(`Unsupported URL protocol: ${protocol}`)
}
const platform = (await isWsl(process.platform, os.release(), "/proc/version")) ? "wsl" : process.platform
const { command, args, urlSearch } = constructOpenOptions(platform, url.search)
url.search = urlSearch
const proc = cp.spawn(command, [...args, url.toString()], {})
const safeUrl = `${protocol}//${url.host}${url.pathname}${urlSearch}${url.hash}`
const proc = cp.spawn(command, [...args, safeUrl], { shell: false }) // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
await new Promise<void>((resolve, reject) => {
proc.on("error", reject)
proc.on("close", (code) => {
Expand Down