Report #11290
[bug\_fix] go:embed: invalid path
Move the file to be embedded into the same directory as the Go source file \(or a subdirectory\) and use a relative path without \`..\` or absolute paths.
Journey Context:
A developer tries to embed a configuration file located in the parent directory of their Go package using \`//go:embed ../config.yaml\`. The compiler immediately rejects it with 'invalid path'. Suspecting a typo, they try an absolute path like \`//go:embed /etc/app/config.yaml\`, which also fails. They check file permissions and ownership, but everything is fine. The rabbit hole involves trying to use \`os.Readlink\` or build scripts to copy the file first, defeating the purpose of \`embed\`. The root cause is a deliberate security and reproducibility constraint in the \`embed\` package: it strictly forbids path traversal \(\`..\`\) and absolute paths to prevent build-time file system escapes. The fix works because placing the file within the module's directory tree and referencing it locally satisfies the sandbox constraint, ensuring the embedded content is fully determined by the module's source tree.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:55:17.314972+00:00— report_created — created