Skip to content

Filesystem Directory Transversal Issue - TruffleHog Fails to Discover Secrets #5039

@Archer36

Description

@Archer36

TruffleHog Version

trufflehog 3.95.5 (brew)

Trace Output

https://gist.github.com/Archer36/67d13077055a68131b7306d0e7ddcacd

Expected Behavior

The presence of a sibling directory should not affect whether another sibling directory is traversed and scanned.

Given:

trufflehog-repro/
├── blue-team/
│   └── project-notes.txt
└── blue-team-deprecated/
    └── AWSCredentials.txt

TruffleHog should traverse and scan blue-team-deprecated/AWSCredentials.txt regardless of whether blue-team exists.

Actual Behavior

When a sibling directory named blue-team exists, TruffleHog discovers the directory blue-team-deprecated but does not descend into it.

As a result:

  • AWSCredentials.txt is never enumerated.
  • AWSCredentials.txt is never scanned.
  • No findings are produced.

If blue-team is renamed to blue-team2, TruffleHog immediately traverses into blue-team-deprecated, scans AWSCredentials.txt, and reports the expected AWS finding.

Removing blue-team entirely produces the same result.

Steps to Reproduce

  1. Create the following directory structure:
trufflehog-repro/
├── blue-team/
│   └── project-notes.txt
└── blue-team-deprecated/
    └── AWSCredentials.txt
  1. Populate AWSCredentials.txt with fake AWS credentials:
AWS_ACCESS_KEY_ID=AKIA7QW9K2M4X8N5R3TZ
AWS_SECRET_ACCESS_KEY=Vw8rL3qP9zNxY2mK7cTfH5sJ1aBdE6uQ4gWpR0xZ
  1. Run:
trufflehog filesystem trufflehog-repro --log-level=5
  1. Observe:

    • No findings are reported.
    • Trace output shows blue-team-deprecated being discovered but not traversed.
  2. Rename:

mv trufflehog-repro/blue-team trufflehog-repro/blue-team2
  1. Run the same scan again:
trufflehog filesystem trufflehog-repro --log-level=5
  1. Observe:

    • AWSCredentials.txt is enumerated and scanned.
    • An AWS finding is reported.
  2. Rename the directory back to blue-team.

  3. Run the scan again.

  4. Observe that the finding disappears.

Environment

  • OS: macOS 15.5
  • TruffleHog Version: 3.95.5

Additional Context

This issue was originally encountered while scanning a SharePoint export, but was reduced to a minimal reproduction that does not require SharePoint data or real credentials.

The issue appears to be related to directory traversal rather than detector behavior.

The key observation from the trace logs is:

Failing case (blue-team exists):

Entry found is a directory
path:"trufflehog-repro/blue-team"

Entry found is a file
path:"trufflehog-repro/blue-team/project-notes.txt"

Entry found is a directory
path:"trufflehog-repro/blue-team-deprecated"

At this point traversal stops. The scanner never enters blue-team-deprecated and never enumerates AWSCredentials.txt.

Successful case (blue-team2 exists):

Entry found is a directory
path:"trufflehog-repro/blue-team-deprecated"

Entry found is a file
path:"trufflehog-repro/blue-team-deprecated/AWSCredentials.txt"

scanning file
path:"trufflehog-repro/blue-team-deprecated/AWSCredentials.txt"

The scanner traverses into the directory, scans the file, and reports the expected finding.

The behavior appears deterministic:

Layout Findings
blue-team + blue-team-deprecated 0
blue-team2 + blue-team-deprecated 1
blue-team-deprecated only 1

This suggests that the existence of a sibling directory whose name is a prefix of another sibling directory may affect filesystem traversal.

References

None currently.

I attached a bash script to help create the test environment.

th-bug.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    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