Skip to content

fix: zero sensitive byte slices after use across all store backends#492

Merged
Benehiko merged 2 commits intomainfrom
zero/out
Mar 17, 2026
Merged

fix: zero sensitive byte slices after use across all store backends#492
Benehiko merged 2 commits intomainfrom
zero/out

Conversation

@Benehiko
Copy link
Member

Replace deferred and manual clear() calls inside loop bodies with helper methods (loadSecret, tryDecrypt) so that a single defer clear() covers all exit paths per invocation. Also fixes two bugs in store/posixage where defer clear() inside a loop body deferred zeroing until function return rather than end of each iteration.

Affected: keychain (darwin/linux/windows), posixage, plugins/pass.

Replace deferred and manual clear() calls inside loop bodies with
helper methods (loadSecret, tryDecrypt) so that a single defer clear()
covers all exit paths per invocation. Also fixes two bugs in
store/posixage where defer clear() inside a loop body deferred zeroing
until function return rather than end of each iteration.

Affected: keychain (darwin/linux/windows), posixage, plugins/pass.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
@Benehiko Benehiko requested a review from joe0BAB March 17, 2026 15:00
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Assessment: 🟢 APPROVE

This PR correctly addresses sensitive data cleanup by refactoring defer clear() calls from inside loop bodies into dedicated helper methods. The changes ensure that sensitive byte slices are zeroed on all exit paths.

Key improvements:

  • ✅ Fixes two defer-in-loop bugs in store/posixage where clear() was deferred to function return instead of iteration end
  • ✅ New helper methods (loadSecret, tryDecrypt) encapsulate sensitive data handling with proper defer clear() placement
  • ✅ Consistent cleanup pattern across all keychain backends (darwin, linux, windows)
  • ✅ All error paths correctly clean up sensitive data before returning

No bugs or regressions identified in the changed code.

Findings

No issues found. The refactoring is sound and improves security hygiene.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
@Benehiko Benehiko merged commit 3717adf into main Mar 17, 2026
29 of 32 checks passed
@Benehiko Benehiko deleted the zero/out branch March 17, 2026 15:35
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.

2 participants