Skip to content

Security: Insecure Temporary File Creation with Predictable Path#2045

Open
tomaioo wants to merge 1 commit into
speakeasy-api:mainfrom
tomaioo:fix/security/insecure-temporary-file-creation-with-pr
Open

Security: Insecure Temporary File Creation with Predictable Path#2045
tomaioo wants to merge 1 commit into
speakeasy-api:mainfrom
tomaioo:fix/security/insecure-temporary-file-creation-with-pr

Conversation

@tomaioo
Copy link
Copy Markdown

@tomaioo tomaioo commented May 20, 2026

Summary

Security: Insecure Temporary File Creation with Predictable Path

Problem

Severity: Medium | File: internal/defaultcodesamples/defaultcodesamples.go:L38

In internal/defaultcodesamples/defaultcodesamples.go, the code creates a temporary file using os.TempDir() with a hardcoded filename defaultcodesamples.js. This is predictable and could lead to a race condition or symlink attack if an attacker can create this file before the program does. The file is written with 0o644 permissions and then executed via exec.Command.

Solution

Use os.CreateTemp or os.MkdirTemp to create a temporary directory with a random name, then write the file there. This prevents predictable path attacks. Also ensure the temporary directory is cleaned up after execution.

Changes

  • internal/defaultcodesamples/defaultcodesamples.go (modified)

In `internal/defaultcodesamples/defaultcodesamples.go`, the code creates a temporary file using `os.TempDir()` with a hardcoded filename `defaultcodesamples.js`. This is predictable and could lead to a race condition or symlink attack if an attacker can create this file before the program does. The file is written with `0o644` permissions and then executed via `exec.Command`.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant