mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-19 08:01:17 +00:00
fix(security): add path traversal defense-in-depth to uploadFile (#1988)
Add `|| remotePath.includes("..")` check to hetzner, digitalocean,
and aws uploadFile functions. The regex `/^[a-zA-Z0-9/_.~-]+$/`
allows `.` characters, so paths like `../../etc/passwd` pass the
regex but are path traversal attempts. gcp, daytona, and sprite
already include this explicit check — this makes all providers
consistent.
Agent: code-health
Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
2eb623e386
commit
e13d809f37
3 changed files with 3 additions and 3 deletions
|
|
@ -1086,7 +1086,7 @@ export async function runServerCapture(cmd: string, timeoutSecs?: number): Promi
|
|||
}
|
||||
|
||||
export async function uploadFile(localPath: string, remotePath: string): Promise<void> {
|
||||
if (!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath)) {
|
||||
if (!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath) || remotePath.includes("..")) {
|
||||
throw new Error(`Invalid remote path: ${remotePath}`);
|
||||
}
|
||||
const keyOpts = getSshKeyOpts(await ensureSshKeys());
|
||||
|
|
|
|||
|
|
@ -1040,7 +1040,7 @@ export async function runServerCapture(cmd: string, timeoutSecs?: number, ip?: s
|
|||
|
||||
export async function uploadFile(localPath: string, remotePath: string, ip?: string): Promise<void> {
|
||||
const serverIp = ip || doServerIp;
|
||||
if (!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath)) {
|
||||
if (!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath) || remotePath.includes("..")) {
|
||||
logError(`Invalid remote path: ${remotePath}`);
|
||||
throw new Error("Invalid remote path");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ export async function runServerCapture(cmd: string, timeoutSecs?: number, ip?: s
|
|||
|
||||
export async function uploadFile(localPath: string, remotePath: string, ip?: string): Promise<void> {
|
||||
const serverIp = ip || hetznerServerIp;
|
||||
if (!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath)) {
|
||||
if (!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath) || remotePath.includes("..")) {
|
||||
logError(`Invalid remote path: ${remotePath}`);
|
||||
throw new Error("Invalid remote path");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue