Skip to content

use securejoin.SecureJoin instead of filepath.Join for containerID path construction #791

Description

@Syedowais312

Description

As discussed in #714, filepath.Join is used to construct container state directory paths from user-controlled containerID input:

  • pkg/unikontainers/unikontainers.go New(): filepath.Join(rootDir, containerID)
  • pkg/unikontainers/unikontainers.go Get(): filepath.Join(rootDir, containerID)
  • cmd/urunc/delete.go ErrNotExist fallback: filepath.Join(rootDir, containerID)

While #726 (validateID) blocks character-based injection, filepath.Join does not protect against symlink-based path escapes. If rootDir or any component in the path is a symlink pointing outside the intended directory, filepath.Join follows it silently. securejoin.SecureJoin resolves the full path within the root boundary, refusing to escape even through symlinks.

Proposed change

Replace the three filepath.Join(rootDir, containerID) calls with securejoin.SecureJoin(rootDir, containerID) and add github.com/cyphar/filepath-securejoin as a direct dependency.

I'd be happy to work on this if it sounds good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions