Skip to content

Commit c6b6d25

Browse files
committed
fix(api): drop user-derived prefix from /ingest/json tempfile
CodeQL flagged the (whitelist-sanitised) safe_stem as "uncontrolled data in path expression". The readable-filename feature was debug ergonomics, not a contract — the URL and source already live inside the file body. Use NamedTemporaryFile's random default name instead. Tests untouched (the contract is the file contents, not the path).
1 parent 798f5c3 commit c6b6d25

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

knowledge-graph-api/api/routes/ingest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ async def ingest_json(body: IngestJsonRequest) -> IngestResult:
146146
Returns:
147147
An ``IngestResult`` summary.
148148
"""
149-
safe_stem = "".join(
150-
c if c.isalnum() or c in "-_ " else "_" for c in body.title
151-
)[:60].strip() or "article"
152-
153149
serialised = (
154150
f"{body.title}\n\n"
155151
f"{body.body}\n\n"
@@ -159,12 +155,16 @@ async def ingest_json(body: IngestJsonRequest) -> IngestResult:
159155
f"Published: {body.published_at.isoformat()}\n"
160156
)
161157

158+
# NamedTemporaryFile defaults: random suffix in the OS temp dir. We
159+
# deliberately do NOT derive the path from request fields — even a
160+
# whitelist-sanitised body field would still trip CodeQL's
161+
# "uncontrolled data in path expression" check, and the readable
162+
# filename is debug-only (the URL/source live in the file body).
162163
tmp_path: str | None = None
163164
try:
164165
with tempfile.NamedTemporaryFile(
165166
delete=False,
166167
suffix=".txt",
167-
prefix=safe_stem + "_",
168168
mode="w",
169169
encoding="utf-8",
170170
) as tmp:

0 commit comments

Comments
 (0)