Skip to content

fix: correct defects found while retiring SonarCloud - #1711

Merged
MuncleUscles merged 1 commit into
v0.123-devfrom
fix/harvested-defects
Jul 23, 2026
Merged

MuncleUscles merged 1 commit into
v0.123-devfrom
fix/harvested-defects

Conversation

@MuncleUscles

Copy link
Copy Markdown
Member

Five verified defects, harvested from a SonarCloud triage sweep before that project is retired (see #1710). Independent fixes, reviewable separately in the diff.

Context on the sweep: 198 findings triaged, 11 real (~1 in 18). Notably, all 70 VULNERABILITY-type findings yielded zero real defects. Two of the five below were found while checking a Sonar finding rather than being flagged by it.

1. CORS advertised credentialed access to any origin

fastapi_server.py had allow_origins=["*"] together with allow_credentials=True. Starlette responds by echoing the caller's Origin rather than a literal *, so any website could make credentialed cross-origin requests to hosted Studio.

Verified that credentials are not needed: authentication is the X-API-Key header (rate_limit_middleware.py:64), there is no set_cookie anywhere in the RPC backend, and the frontend does not use withCredentials. A custom header is already permitted by allow_headers=["*"]. Set allow_credentials=False; origins are unchanged, since this is deliberately a public RPC.

Sonar did not flag this. It was found while investigating the middleware-order issue below.

2. Rate-limit rejections carried no CORS headers

add_middleware inserts at index 0, so the last middleware added is outermost. CORS was added first and RateLimit second, making RateLimit outermost — its 429 short-circuit returned without passing back out through CORS, so browsers saw an opaque network/CORS failure instead of a readable 429. The inline comment asserted the opposite of what the code did.

RateLimit is now added first (inner), CORS last (outermost), and the comment states the actual relationship.

3. Consensus events were gated on a comparison that never matched

redis_worker_handler.py tested log_event.scope.value in ["TRANSACTION", "CONSENSUS"], but the enum's values are "Transaction" and "Consensus". The same class compared them correctly elsewhere. The test was therefore always false, and publication was gated solely on transaction_hash — scope-only consensus events were silently never published.

Present in three places (the sweep identified two; worker_handler.py had it as well). All now compare against EventScope members rather than string literals, so a value rename cannot silently reintroduce it.

4. Readiness jitter was identical across replicas

health.py seeded jitter with random.Random(os.getpid()). The stated intent is jitter stable within a process but different between processes, so replicas don't flip readiness in lockstep — but containerised replicas commonly share a PID, so every pod computed the same jitter and would withdraw readiness simultaneously, which is the behaviour the jitter exists to prevent. Now unseeded; per-process stability still comes from the module-level assignment.

5. Two smaller ones

  • transactions_processor.py: if byte_content or len(byte_content) >= 0: — len(x) >= 0 is always true, making the guard a no-op and the following return unreachable. Removed the tautology without changing behaviour. The original intent is ambiguous; this is deliberately not a behavioural change.
  • backend/validators/__init__.py: __all__ exported with_lock, which is defined nowhere, so import * would raise. Latent (no star-import exists today). Confirmed no definition or caller, then removed the entry.

Verification

Backend unit tests pass (56 in the touched files). The new tests were checked against the unfixed code first — 6 of them fail without these changes, so they pin the defects rather than merely passing.

Items 1 and 2 affect a live hosted service; item 2's behaviour is browser-observable and worth a smoke check after deploy.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e60f57d-41b7-4ba3-b77e-f4ea3d40150d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/harvested-defects

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
77.2% Coverage on New Code (required ≥ 80%)
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

CORS advertised credentialed access to any origin and did not decorate
rate-limit rejections; consensus events were gated on a comparison that
never matched; readiness jitter was identical across replicas.
@MuncleUscles
MuncleUscles force-pushed the fix/harvested-defects branch from bbf33a7 to d9ca846 Compare July 23, 2026 18:02
@MuncleUscles
MuncleUscles merged commit c940729 into v0.123-dev Jul 23, 2026
25 of 26 checks passed
@MuncleUscles
MuncleUscles deleted the fix/harvested-defects branch July 23, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant