Repository navigation
Baseline the fastapi SSE keepalive loop after its 0.140.0 rewrite - #7480
Merged
Merged
Conversation
Security audit fails on main with 1 unsuppressed CRITICAL:
CRITICAL C2 polling/beaconing loop detected
Package: fastapi
File: fastapi/routing.py
The same file and check are already baselined, but the entry is keyed on a
digest of the matched code, so fastapi 0.140.0 rewriting the block reopened it.
That is the baseline working as intended, not a stale pin, so the new code
needs its own review rather than a regenerated file.
The flagged block is the SSE keepalive inserter:
async def _keepalive_inserter() -> None:
async with send_keepalive, receive_stream:
try:
while True:
try:
with anyio.fail_after(_PING_INTERVAL):
data = await receive_stream.receive()
await send_keepalive.send(data)
except TimeoutError:
await send_keepalive.send(KEEPALIVE_COMMENT)
except anyio.EndOfStream:
pass
It forwards one in-memory anyio stream to another and emits a keepalive comment
when the read times out. No socket, no outbound host, no fetched command, and it
terminates on EndOfStream. The heuristic matches it on the shape alone, a loop
with a timeout and a send, so it is a false positive.
Adds that one entry. The existing fastapi entry stays, since the requirement is
unpinned and an older resolve still needs it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security auditfails on main. Thepip scan-packages :: studiojob reports one unsuppressed CRITICAL:Why it reopened
The same package, file and check are already in the baseline:
{ "package": "fastapi", "file": "fastapi/routing.py", "check": "C2 polling/beaconing loop detected", "evidence": "L587: while True: sha256:06c2c7f1...", "evidence_hash": "57acd497..." }Entries are keyed on
(package, package-relative file, check, evidence_hash), and the hash is taken over the matched code with theL<NN>:markers stripped. So a line shift alone would not reopen it, but fastapi 0.140.0 rewrote the block and the digest changed. That is the baseline behaving as designed, and it means the new code needs its own review rather than a regenerated file.Reviewing the new code
fastapi/routing.pyat 0.140.0:This is the Server-Sent Events keepalive path. It reads from one in-memory
anyiostream and forwards to another, emittingKEEPALIVE_COMMENTwhen a read exceeds_PING_INTERVAL. There is no socket, no outbound host, no fetched or executed command, and the loop exits onEndOfStream. The heuristic matches on shape alone, an unbounded loop containing a timeout and a send, so this is a false positive in the same way the previous revision was.Change
One entry added, generated by
scan_packages.py --write-baselineagainstfastapi==0.140.0rather than hand-written. The pre-existing fastapi entry is kept, not replaced:studio/backend/requirements/studio.txtlistsfastapiunpinned, so an older resolve still needs the old digest. No other entry is touched, and nothing is removed.Verification
Confirmed the same run reports the CRITICAL with
--no-baseline, so the suppression is doing the work and the finding is genuinely the one under review.