Skip to content

fix(samples): use temp files and extension allowlist in ImageMagick samples - #10399

Open
taeold wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
taeold:fix/imagemagick-path-sanitization
Open

taeold wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
taeold:fix/imagemagick-path-sanitization

Conversation

@taeold

@taeold taeold commented Nov 30, 2026

Copy link
Copy Markdown

Description

Harden path handling and file extension validation across the Java ImageMagick samples (run/image-processing, functions/imagemagick, and functions/v2/imagemagick), and clarify Cloud Run Pub/Sub authentication setup in run/image-processing/README.md.

Changes

  • Update run/image-processing/src/main/java/com/example/cloudrun/PubSubController.java, run/image-processing/src/main/java/com/example/cloudrun/ImageMagick.java, and run/image-processing/README.md (--no-allow-unauthenticated guidance and safe temporary file/extension handling).
  • Update functions/imagemagick/src/main/java/functions/ImageMagick.java and functions/v2/imagemagick/src/main/java/functions/ImageMagick.java to use temporary files and extension allowlisting.

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 samples Issues that are directly related to samples. api: cloudfunctions Issues related to the Cloud Run functions API. api: run Issues related to the Cloud Run API. 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 enhances the security of ImageMagick-based image processing services across Cloud Functions (v1 and v2) and Cloud Run. It mitigates path traversal and argument injection vulnerabilities by replacing hardcoded temporary file paths with safely generated temporary files using Files.createTempFile and validating file extensions against a whitelist. It also ensures proper cleanup of temporary files using a try-finally block with Files.deleteIfExists. Additionally, the Cloud Run service is updated with documentation and comments recommending secure deployment using --no-allow-unauthenticated and IAM-authenticated Pub/Sub push subscriptions. There are no review comments, and I have no further feedback to provide.

@taeold
taeold force-pushed the fix/imagemagick-path-sanitization branch from 5f387da to e5684cf Compare November 30, 2026 22:43
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. api: run Issues related to the Cloud Run API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant