File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -399,6 +399,21 @@ func getUserConfigDir() (string, error) {
399399 return os .UserConfigDir ()
400400}
401401
402+ // ClearFileStreamCache wipes the cached stream secrets from memory by overwriting
403+ // the byte slices with zeros before deleting them from the map.
404+ // This is critical for security to prevent keys from lingering in RAM.
405+ func ClearFileStreamCache () {
406+ fileStreamCache .Range (func (key , value interface {}) bool {
407+ if byte , ok := value .([]byte ); ok {
408+ for i := range byte {
409+ byte [i ] = 0
410+ }
411+ }
412+ fileStreamCache .Delete (key )
413+ return true
414+ })
415+ }
416+
402417// reads a file from the given path, if it is a stream (e.g., /dev/fd/* or /proc/*)
403418// it caches the content in memory to avoid issues with multiple reads from the same stream.
404419func readStreamSafe (path string ) ([]byte , error ) {
Original file line number Diff line number Diff line change @@ -75,6 +75,8 @@ func warnMoreThanOnePositionalArgument(c *cli.Context) {
7575}
7676
7777func main () {
78+ defer age .ClearFileStreamCache ()
79+
7880 cli .VersionPrinter = version .PrintVersion
7981 app := cli .NewApp ()
8082
You can’t perform that action at this time.
0 commit comments