Skip to content

AUDIT-09 — Medium-High — session_id unbounded at the API, VARCHAR(255) in the DB #66

Closed

Description

@getdownandcode

Summary

Severity: Medium-High
Area: Persistence / API
Affected files: agentkit/api/schemas.py:9-18, agentkit/db/models.py:25-29
Suggested branch: fix/session-id-length-validation
Suggested PR title: fix(api): bound session_id at the request boundary

This is finding AUDIT-09 of 18 from a consolidated audit of agentkit/. It is deliberately self-contained so it can be fixed on its own branch with its own PR.

Related findings: Related: AUDIT-08.


AUDIT-09 — Medium-High — session_id unbounded at the API, VARCHAR(255) in the DB

Files

  • agentkit/api/schemas.py:9-18
  • agentkit/db/models.py:25-29

Current code — agentkit/api/schemas.py:9-18

class RunCreateRequest(BaseModel):
    """Payload to initiate a new agent execution run."""

    model_config = ConfigDict(extra="forbid")

    goal: str = Field(..., min_length=1, description="Goal or task description for the agent.")
    session_id: str | None = Field(
        default=None,
        description="Optional conversation session ID to preserve context across multiple runs.",
    )

Current code — agentkit/db/models.py:25-29

    session_id: Mapped[str | None] = mapped_column(
        String(255),
        nullable=True,
        index=True,
    )

Why this is a bug

The API accepts a session_id of any length; the column is VARCHAR(255). A 256+ character session id makes the INSERT in create_run fail with a data-length error → suppressed (AUDIT-08) → the client receives a phantom HTTP 200 succeeded and the run is never stored. The same id is also used verbatim as a Redis key (session:<id>:messages), so an oversized id also becomes an unbounded key.

Pass cases

  • RunCreateRequest.session_id has an explicit maximum length (255) → an over-long id returns HTTP 422 with the validation error, before any agent work starts.
  • An over-long session id never reaches the database or Redis.
  • A 255-character session id is accepted and round-trips (DB + Redis).
  • The DB column length and the API limit are asserted to be equal by a test (so they cannot drift again).
  • A test asserts an over-long session id yields 422 and no run record is created.


Definition of done (per AGENTS.md)

  • New/updated unit and integration tests covering the pass cases above, all passing (pytest).
  • ruff check ., ruff format --check . and mypy agentkit clean.
  • Docstrings updated where behaviour changed; docs/PROGRESS.md updated (status, PR link, commit count, notes).
  • A new ADR in docs/DECISIONS.md if an architectural decision was made.
  • Branch pushed and PR opened (never commit directly to main).

Baseline at the time of writing: pytest is green on main (all tests pass; tests/real/* skipped unless AGENTKIT_REAL_INFRA=1).

Activity

  1. getdownandcode commented on Oct 20, 2026

    @getdownandcode
    OwnerAuthor

    Audit index (18 separate issues, fix one by one)

    ID Issue Severity
    AUDIT-01 #58 Critical
    AUDIT-02 #59 Critical
    AUDIT-03 #60 High
    AUDIT-04 #61 High
    AUDIT-05 #62 High
    AUDIT-06 #63 High/Medium
    AUDIT-07 #64 Medium-High
    AUDIT-08 #65 Medium-High
    AUDIT-09 #66 Medium-High
    AUDIT-10 #67 Medium-High
    AUDIT-11 #68 Medium
    AUDIT-12 #69 Medium
    AUDIT-13 #70 Medium
    AUDIT-14 #71 Medium
    AUDIT-15 #72 Medium
    AUDIT-16 #73 Medium
    AUDIT-17 #74 Low
    AUDIT-18 #75 Low/Deployment

    Each issue is self-contained: current code, reproduction, pass cases, suggested branch and PR title. Reference the relevant one with Fixes #NN in your PR.

  2. HamzaKhanBUIC commented on Oct 20, 2026

    @HamzaKhanBUIC

    Opened PR #80 with the complete fix and regression test suite:

    • Defined SESSION_ID_MAX_LENGTH: int = 255 and bounded RunCreateRequest.session_id with max_length=SESSION_ID_MAX_LENGTH in �gentkit/api/schemas.py.
    • Aligned Run.session_id in �gentkit/db/models.py to use String(SESSION_ID_MAX_LENGTH).
    • Added unit and integration tests verifying over-long IDs (>255 chars) return HTTP 422 before agent execution, 255-character IDs succeed and round-trip across DB and Redis, and asserted that the DB column length equals the API schema max length to prevent schema drift.
    • Verified clean across pytest,
      uff check,
      uff format --check, and mypy agentkit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions