Skip to content

Commit 7c0a0f2

Browse files
committed
fix: path traversal check Python + timeout signal propagation
1 parent c27871b commit 7c0a0f2

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

skills/shieldcode/SKILL.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB
502502
@app.get("/files/{filename}")
503503
async def get_file(filename: str):
504504
requested = (UPLOAD_DIR / filename).resolve()
505-
if not str(requested).startswith(str(UPLOAD_DIR)):
505+
if not str(requested).startswith(str(UPLOAD_DIR) + "/"):
506506
raise HTTPException(status_code=400, detail="Invalid file path")
507507
if not requested.exists():
508508
raise HTTPException(status_code=404, detail="File not found")
@@ -843,7 +843,7 @@ const response = await fetch('https://api.payment.com/charge', {
843843

844844
// SAFE - with timeout, retry, and error handling
845845
async function callWithRetry<T>(
846-
fn: () => Promise<T>,
846+
fn: (signal: AbortSignal) => Promise<T>,
847847
options: { maxAttempts?: number; baseDelayMs?: number; timeoutMs?: number } = {}
848848
): Promise<T> {
849849
const { maxAttempts = 3, baseDelayMs = 200, timeoutMs = 5000 } = options;
@@ -852,7 +852,7 @@ async function callWithRetry<T>(
852852
const controller = new AbortController();
853853
const timeout = setTimeout(() => controller.abort(), timeoutMs);
854854
try {
855-
const result = await fn();
855+
const result = await fn(controller.signal);
856856
clearTimeout(timeout);
857857
return result;
858858
} catch (error) {
@@ -868,11 +868,12 @@ async function callWithRetry<T>(
868868
throw new Error('Unreachable');
869869
}
870870

871-
const response = await callWithRetry(() =>
871+
const response = await callWithRetry((signal) =>
872872
fetch('https://api.payment.com/charge', {
873873
method: 'POST',
874874
headers: { 'Content-Type': 'application/json' },
875875
body: JSON.stringify(data),
876+
signal, // passes abort signal so timeout actually cancels the request
876877
})
877878
);
878879
```

0 commit comments

Comments
 (0)