Skip to content

harden(protocol): bound + charset-constrain the handshake session_id#547

Merged
dsarno merged 1 commit into
mainfrom
harden/session-id-validation
Jun 10, 2026
Merged

harden(protocol): bound + charset-constrain the handshake session_id#547
dsarno merged 1 commit into
mainfrom
harden/session-id-validation

Conversation

@dsarno

@dsarno dsarno commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Wave 2 hardening — review finding ST-4 (#527).

The WebSocket handshake accepted an unbounded, arbitrary session_id from the peer, then used it as a registry key, logged it, and hashed it into telemetry. The plugin only ever produces <slug>@<4hex> (slug is [a-z0-9-], see connection.gd::_make_session_id), so a ^[A-Za-z0-9._@-]{1,128}$ pattern rejects only malformed/non-plugin clients while accepting every legitimate id. A bad id now fails at the Pydantic boundary instead of populating the registry.

Test

  • tests/unit/test_protocol.py: canonical slug@hex accepted; empty / whitespace / path-separator / over-128 / non-ASCII rejected.
  • Full handshake/transport/integration suite (403) green; ruff clean.

Closes #527.

🤖 Generated with Claude Code

The WebSocket handshake accepted an unbounded, arbitrary session_id from the
peer, then used it as a registry key, logged it, and hashed it into telemetry.
The plugin only ever produces "<slug>@<4hex>" (slug is [a-z0-9-]), so a
pattern of ^[A-Za-z0-9._@-]{1,128}$ rejects only malformed or non-plugin
clients while accepting every real id. A bad id now fails the handshake at the
Pydantic boundary instead of populating the registry.

Addresses review finding ST-4 (#527).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the “ST-4” hardening from #527 by validating the WebSocket handshake session_id at the Pydantic model boundary, preventing unbounded/arbitrary peer-provided IDs from flowing into the session registry, logs, and telemetry.

Changes:

  • Constrain HandshakeMessage.session_id to ^[A-Za-z0-9._@-]{1,128}$ via Pydantic Field(pattern=...).
  • Add unit tests asserting canonical plugin-style IDs are accepted and malformed/oversized/non-ASCII IDs are rejected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/godot_ai/protocol/envelope.py Adds bounded/charset validation for handshake session_id in the protocol envelope model.
tests/unit/test_protocol.py Adds targeted validation tests covering accepted and rejected session_id inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dsarno dsarno merged commit 9a92737 into main Jun 10, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[robustness] WebSocket handshake session_id is unvalidated and unbounded

2 participants