Repository navigation
Conversation
The url and the body of send-* hooks were expanded with the profile
environment at runtime, but header values were sent as written, so a
header such as "Authorization: Basic ${SECRET}" could not take its
secret from env or env-file. Expand header values like the body, and
mask confidential headers after expansion so the expanded secret does
not show in dry-run and debug output.
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #704 +/- ##
=======================================
Coverage 85.41% 85.41%
=======================================
Files 161 161
Lines 10336 10338 +2
=======================================
+ Hits 8828 8830 +2
Misses 1508 1508
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
🟡 Changes recommended
Expanded secrets can leak through custom-header logging, while multiline substitutions can prevent hook delivery and unconditional expansion can break existing credentials.
3 open issues
What changed in this PR
This PR enables runtime variable expansion in HTTP hook headers, addressing the header-related case in #663 so hooks can use secrets loaded from profile environment files.
Changes:
- Expand header values using the same runtime variables as request bodies.
- Track expanded confidential values for masking in dry-run and debug logs.
- Add header expansion and dry-run masking tests, and document the syntax.
| File | Description |
|---|---|
monitor/hook/sender.go |
Expands header values and updates confidential-value masking. |
monitor/hook/sender_test.go |
Tests environment and profile-name expansion plus dry-run secret masking. |
docs/content/configuration/http_hooks.md |
Documents runtime header expansion and dollar-sign escaping. |
Review effort: Balanced
Comment on lines
+119
to
+120
| if header.Value.IsConfidential() { | ||
| masked[value] = header.Value.String() |
| continue | ||
| } | ||
| req.Header.Add(header.Name, header.Value.Value()) | ||
| value := resolveBody(header.Value.Value(), ctx, env) |
| continue | ||
| } | ||
| req.Header.Add(header.Name, header.Value.Value()) | ||
| value := resolveBody(header.Value.Value(), ctx, env) |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Fixes #663
The issue tries to send
Authorization: Basic <secret>from asend-afterhook with the secret in anenv-file. Template syntax ({{ .Env.SECRET }}) runs before the env file is loaded, and the runtime${SECRET}syntax does not work either:Sender.Sendexpands the url (resolveURL) and the body (resolveBody) with the profile environment, but adds every header withheader.Value.Value()as written.Change:
resolveBody, so they get the same variables as the body: the profile environment (OS,env-file,env),PROFILE_NAME,PROFILE_COMMANDand, insend-after-fail/send-finally, theERROR*ones.$$still gives a literal$.stringifyHeadersnow takes a map from the expanded value to its masked form, built while the headers are added.http_hooks.mdsays the header values are expanded too.End to end with a stub
restic,env-filecontainingHOOK_CREDENTIALS=dXNlcjpwYXNzand asend-beforeheadervalue: 'Basic ${HOOK_CREDENTIALS}', the header received by a local HTTP server:and
--dry-run backupstill printsAuthorization: ×××.Test:
TestHeaderEnvchecks an env variable and$PROFILE_NAMEin header values, then runs the same hook in dry-run with a memory logger and checks the secret is not in the logs. It fails on master (actual: "Basic ${TEST_SECRET}").I used an AI assistant (Claude) to help with this change; I reviewed it and ran the checks above myself.