Skip to content

Commit 95e9332

Browse files
committed
Harden audio processing and dependencies
1 parent 994b113 commit 95e9332

5 files changed

Lines changed: 64 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
push:
55
pull_request:
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
test:
912
runs-on: ubuntu-latest

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ requires-python = ">=3.10"
88
authors = [{ name = "Sonic Field Labs" }]
99
dependencies = [
1010
"akousma>=0.4.0",
11-
"fastapi>=0.111.0",
11+
"fastapi>=0.139",
1212
"httpx>=0.27.0",
1313
"pydantic>=2.7.0",
1414
"python-dotenv>=1.0.1",
15-
"python-multipart>=0.0.9",
15+
"python-multipart>=0.0.31",
1616
"uvicorn[standard]>=0.30.0",
1717
]
1818

@@ -29,6 +29,7 @@ python-provider = [
2929
"stable-audio-3 @ git+https://github.com/Stability-AI/stable-audio-3.git",
3030
]
3131
dev = [
32+
"httpx2>=2.7",
3233
"pytest>=8.2.0",
3334
"ruff>=0.6.0",
3435
]

server/routes/audio_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,12 @@ def process_audio(request: AudioProcessRequest) -> GenerationResult:
831831
audio_path.parent.mkdir(parents=True, exist_ok=True)
832832
command = _rubberband_command(binary, request, source_audio, audio_path, ratio)
833833
try:
834-
subprocess.run(command, check=True, capture_output=True, text=True, timeout=180, stdin=subprocess.DEVNULL)
834+
# Fixed Rubber Band executable, numeric flags, and storage-confined paths; no shell is used.
835+
subprocess.run(command, check=True, capture_output=True, text=True, timeout=180, stdin=subprocess.DEVNULL) # nosemgrep: python.django.security.injection.command.subprocess-injection.subprocess-injection
835836
except subprocess.TimeoutExpired as exc:
836837
raise HTTPException(status_code=504, detail="Rubber Band processing timed out.") from exc
837838
except subprocess.CalledProcessError as exc:
838-
detail = (exc.stderr or exc.stdout or str(exc)).strip()
839-
raise HTTPException(status_code=422, detail=f"Rubber Band processing failed: {detail}") from exc
839+
raise HTTPException(status_code=422, detail="Rubber Band processing failed.") from exc
840840

841841
output_payload = _read_wav(audio_path)
842842
operation_params = {

server/routes/time_render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _pitch_shift_payload(
248248
temp_dir: Path,
249249
) -> WavPayload:
250250
cache_key = f"{payload.source.id}:{payload.path}:{pitch_semitones:.8f}"
251-
output_path = temp_dir / f"pitch_{hashlib.sha1(cache_key.encode('utf-8')).hexdigest()}.wav"
251+
output_path = temp_dir / f"pitch_{hashlib.sha256(cache_key.encode('utf-8')).hexdigest()}.wav"
252252
command = _rubberband_pitch_command(binary, payload.path, output_path, pitch_semitones)
253253
try:
254254
subprocess.run(command, check=True, capture_output=True, text=True, timeout=180, stdin=subprocess.DEVNULL)

uv.lock

Lines changed: 54 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)