jfrog / jfrog/frogbot

Python Incorrect directory boundary check using strings.HasPrefix

Open
#1,030 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
372
Forks
107
Avg merge
2d 20h
Merged PRs (30d)
5

Description

Describe the bug

Bug 2: Incorrect directory boundary check using strings.HasPrefix

Description

The code attempts to prevent path traversal with:

strings.HasPrefix(filepath.Clean(fullPath), wd)

This is unsafe because paths like /repo2/... also match the prefix /repo.

Impact
  • Potential directory traversal.
  • False positives and false negatives during path validation.
Suggested Fix

Use filepath.Rel() and reject paths starting with .., or ensure the prefix check includes a path separator boundary.

Current behavior

The code attempts to prevent directory traversal by checking whether the cleaned path string starts with the working directory string. This check can incorrectly succeed for paths outside the working directory that merely share the same string prefix.

Reproduction steps

Run as Is

Expected behavior

Path traversal protection should be correct and filesystem-aware:

Accept only paths that resolve inside the workspace.

Reject paths outside the workspace, including prefix-trick cases (e.g., /repo2 when workspace is /repo).
This should be implemented using robust path comparison (e.g., filepath.Rel, realpath checks, and separator-aware boundaries).

JFrog Frogbot version

LATEST

Package manager info

Python

Git provider

GitHub

JFrog Frogbot configuration yaml file

Default

Operating system type and version

ALL

JFrog Xray version

LATEST

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the Go codebase for strings.HasPrefix(filepath.Clean(fullPath), wd) and inspect the surrounding path-validation flow and any existing tests. Add regression coverage for a workspace such as /repo and an outside path such as /repo2, then run the relevant Go tests. Done means paths resolve inside the workspace while prefix-trick paths are rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.