Skip to content

Harden memory Reader against path traversal (CodeQL go/path-injection) #10

Description

@prashar32

CodeQL (GitHub code scanning) reports two high-severity go/path-injection alerts:

User-supplied namespace/name (from GET /v1/memory and /v1/memory/entry query params) flow into file operations in Reader.Read/List.

Current state

safeJoin does filepath.Clean + a prefix check that the resolved path stays under the root, and a live test confirms ../../etc/hosts is rejected (HTTP 400). So traversal is blocked today — but CodeQL's taint analysis does not recognise a prefix-string check as a sanitizer, so the alerts stay open.

Proposed fix (standard approach)

  • Validate the cleaned relative path with filepath.IsLocal (rejects .., absolute, and escaping paths; CodeQL recognises it as a path-injection barrier), keeping the existing prefix check as defense-in-depth.
  • (Optional, stronger: on Go 1.24+, switch to os.Root / os.OpenInRoot, which is traversal-safe by construction.)
  • Add a regression test asserting the alert pattern is closed.

Alerts: /security/code-scanning/3 and /security/code-scanning/4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions