Skip to content

fix(examples): any text reaches the mongo stock filter as a sku (CodeQL go/sql-injection) #255

Closed

Description

@jpfaria

CodeQL (go/sql-injection) flags the MongoDB stock datastores: the sku from the request goes straight into the filter.

  • alert 9 and 10: examples/stock/internal/pkg/datastore/stock/mongodb/datastore.go (new in the 1.7.0 release PR release: 1.7.0 #254)
  • alert 5: docs/site/example/shop/internal/pkg/datastore/stock/mongodb/datastore.go (already on main)

In Go the sku is a string, so Mongo never reads it as an operator: no real injection. Still, the example app takes any text as a sku ($gt, spaces, empty) and sends it to the datastore.

Intended behavior:

  • examples/stock: a sku outside [a-z0-9-] (1 to 64 chars) is rejected as Bad Request / InvalidArgument at every door, before any datastore.
  • both mongodb datastores match the sku with an explicit $eq.
  • the three alerts are dismissed as false positive, pointing to this issue.

Activity

  1. added this to the 1.7.0 milestone on Oct 20, 2026
  2. self-assigned this
    on Oct 20, 2026
  3. added a commit that references this issue on Oct 20, 2026
  4. jpfaria commented on Oct 20, 2026

    @jpfaria
    ContributorAuthor

    Merged in #258 (935ea02): RED first in examples/stock/cmd/api/main_test.go (400/InvalidArgument/tool error for $gt, upper case, space, 65 chars; the app answered 201/200/404), then entity.ValidSKU in the creator/finder/reserver services and $eq in both mongo datastores (README + site too). go test ./... green in examples/stock and the site shop; TestAPIMongo green on mongo:7. Next: dismiss CodeQL alerts 5, 9, 10 as false positive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions