mirror of
https://github.com/gofiber/storage.git
synced 2025-12-19 00:38:24 +08:00
Also copy value in Get() to prevent caller mutations
Returning the stored slice directly allows callers to mutate the stored data, which defeats the purpose of the defensive copying in Set(). Since this package doesn't have access to gofiber/utils, we manually copy the slice using make() and copy(). This completes the fix by ensuring stored data cannot be corrupted either on input (Set) or accessed mutably on output (Get).
This commit is contained in:
@@ -53,7 +53,10 @@ func (s *Storage) Get(key string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return v.data, nil
|
||||
// Return a copy to prevent callers from mutating stored data
|
||||
valCopy := make([]byte, len(v.data))
|
||||
copy(valCopy, v.data)
|
||||
return valCopy, nil
|
||||
}
|
||||
|
||||
// GetWithContext gets value by key (dummy context support)
|
||||
|
||||
Reference in New Issue
Block a user