Skip to content

[Bug]: PostgresAgentStateStore.listSessionIds uses unescaped LIKE pattern, wildcard user ids list other users' sessions #4329

Done

Description

@blueice1986

Environment

  • AgentScope Java: main @ b515982 (2026-11-22)
  • Module: agentscope-extensions-postgresql
  • Java: 21

Problem

PostgresAgentStateStore.listSessionIds builds its LIKE pattern by raw string
concatenation (PostgresAgentStateStore.java:686):

stmt.setString(1, prefix + "%");   // prefix = normalizeUser(userId) + ":"

PostgreSQL treats _ and % as LIKE wildcards, so user ids containing these
characters widen the prefix match across users.

Reproduction (logical)

  • listSessionIds("user_1") → pattern user_1:% also matches slot id
    userA1:s → user userA1's sessions appear in user_1's list.
  • listSessionIds("100%") → pattern 100%:% matches every slot starting
    with 100, e.g. 100foo:anything.
  • listSessionIds(null) → pattern __anon__:%; the 6 underscores in
    __anon__ match any 6 single characters, so slot ids like 12anon3456:s
    are cross-listed too.

Root cause

The user segment is never escaped for LIKE (\, %, _).

Suggested fix

Escape the pattern with PostgreSQL's default LIKE escape character \
(mirroring the likePrefixPattern helper already used by the MySQL JDBC
store, JdbcStore.java), as suggested by a maintainer in the #3233 review:
"consider porting the JDBC escape helper in a follow-up".

A PR is on the way and will reference this issue.

Activity

  1. added a commit that references this issue on Nov 26, 2026
    31d3200
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions