Skip to content

fix(functions): prevent path traversal in http-form-data sample - #10398

Open
taeold wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
taeold:fix/http-form-data-path-traversal
Open

taeold wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
taeold:fix/http-form-data-path-traversal

Conversation

@taeold

@taeold taeold commented Nov 30, 2026

Copy link
Copy Markdown

Description

Prevent path traversal when saving and cleaning up multipart upload filenames in functions/http/http-form-data.

Changes

  • Sanitize uploaded multipart filenames in functions/http/http-form-data/src/main/java/functions/HttpFormData.java before constructing temporary file paths.
  • Add 3 JUnit tests in functions/http/http-form-data/src/test/java/functions/HttpFormDataTest.java.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.
  • Tests pass: mvn clean verify required (awaiting CI; mvn unavailable in local environment)
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only

Compliance & Style

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample

Post-Approval Actions

  • Please merge this PR for me once it is approved

@taeold
taeold requested review from a team and yoshi-approver as code owners November 30, 2026 22:34
@product-auto-label product-auto-label Bot added api: cloudfunctions Issues related to the Cloud Run functions API. samples Issues that are directly related to samples. labels Nov 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements path traversal prevention when processing uploaded files in HttpFormData.java by sanitizing filenames and validating that the resolved file paths remain within the temporary directory. It also adds corresponding unit tests in HttpFormDataTest.java. The reviewer provided two valuable suggestions: first, to replace backslashes with forward slashes in filenames to ensure consistent behavior across Unix and Windows environments; second, to use toRealPath() instead of toAbsolutePath().normalize() in tests to prevent potential flakiness on platforms with symlinked temporary directories (such as macOS).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: cloudfunctions Issues related to the Cloud Run functions API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant