Skip to content

FileArtifactService: user_id and session_id not validated for path traversal #5110

Closed

Description

@vnykmshr

_resolve_scoped_artifact_path validates the filename against traversal, but _base_root and _session_artifacts_dir use user_id and session_id directly in Path() construction without the same check.

A user_id or session_id containing ../ segments builds a scope root outside root_dir. The filename guard then validates against the already-escaped scope root, so it doesn't catch the escape.

GcsArtifactService and InMemoryArtifactService use string keys, not filesystem paths - only FileArtifactService is affected.

Activity

  1. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Apr 2, 2026
  2. added theissue type on Apr 2, 2026
  3. added 2 commits that reference this issue on Apr 8, 2026
    9957c52
    fa1c93f
  4. surajksharma07 commented on Apr 11, 2026

    @surajksharma07
    Collaborator

    @vnykmshr The missing guard in _base_root() and _scope_root() is the root cause here.

    While PR #5206 is under review, a workaround worth trying: subclass FileArtifactService and add a resolve() + relative_to() check on user_id and session_id before the path is constructed — same pattern already used for filenames in _resolve_scoped_artifact_path(), so it should slot in cleanly.

    Could you give that a try and let us know if it blocks both traversal vectors on your end?
    If it holds up, it'd be great to include it as a test case in the PR too!

  5. vnykmshr commented on Apr 11, 2026

    @vnykmshr
    Author

    @surajksharma07 _validate_path_segment in #5111 does exactly that: resolve(strict=False) + relative_to() on both user_id and session_id before the path is built, same guard as _resolve_scoped_artifact_path uses for filenames. Blocks both vectors.

    Tests: 7 parametrized cases covering user_id, session_id, and the delete path (confirms shutil.rmtree is unreachable with a crafted session_id).

    PR's been open since Apr 2 if it helps.

  6. surajksharma07 commented on Apr 12, 2026

    @surajksharma07
    Collaborator

    @vnykmshr Apologies for the overlap! The _validate_path_segment approach in #5111 is exactly the right fix, and 7 parametrized tests covering both the user_id/session_id vectors and the shutil.rmtree path is really thorough work.

    I'll flag both #5111 and #5206 for prioritized review given this has been sitting unpatched since Apr 2.

  7. surajksharma07 commented on Apr 12, 2026

    @surajksharma07
    Collaborator

    @DeanChensj Please have a look into it once.

  8. added a commit that references this issue on Apr 13, 2026
    cbcb5e6
  9. added 2 commits that reference this issue on Apr 13, 2026
    951a238
    44273e0
  10. added a commit that references this issue on Apr 21, 2026
    df92e64
  11. added a commit that references this issue on Aug 11, 2026
    7426c92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

needs review[Status] The PR/issue is awaiting review from the maintainerservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions