34 Commits

Author SHA1 Message Date
Jason McNeil
4e90d76c39 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).
2025-10-31 07:27:45 -03:00
Jason McNeil
3b32d861ca Merge branch 'main' into fix/memory-storage-pool-corruption 2025-10-31 05:57:54 -03:00
Jason McNeil
a3e93a4171 Fix: Prevent memory corruption from pooled buffers in memory storage
Problem:
The memory storage uses string keys and byte slice values directly in
a Go map without copying them. When these strings/slices are backed by
pooled buffers (from sync.Pool used by Fiber for performance), the map
keys and values can become corrupted when those buffers are reused.

Root Cause:
1. Fiber v3 uses sync.Pool extensively for byte buffer reuse
2. Strings created from pooled buffers point to the underlying pooled memory
3. When used as Go map keys without copying, these strings share the pooled buffer
4. When the buffer is returned to the pool and reused, the map key gets corrupted
5. This causes intermittent failures where sessions/CSRF tokens cannot be found

Solution:
Copy both the key (string) and value ([]byte) before storing in the map.
Since this package doesn't have access to gofiber/utils, we use manual copying:
- Key: string([]byte(key)) - creates a new string with a new backing array
- Value: make new slice and copy bytes

Testing:
- Before fix: ~8% pass rate with ginkgo --repeat=100
- After fix: 100% pass rate with ginkgo --repeat=200
- No corrupted keys found in storage after fix

Impact:
- Performance: Minimal - one string copy and one byte slice copy per Set
- Safety: Prevents entire class of memory corruption bugs
- Consistency: Aligns with the fix applied to gofiber/fiber internal storage
2025-10-31 05:48:39 -03:00
Muhammed Efe Cetin
75b43b2ac4 add context support to more storages 2025-06-25 14:13:21 +03:00
Juan Calderon-Perez
22f4401661 Add fix to verify Keys are expired during Keys() call. 2023-10-29 21:00:43 -04:00
Juan Calderon-Perez
7921dc7e37 Add support for Keys() to Memory Driver 2023-10-29 20:42:46 -04:00
Juan Calderon-Perez
9570205b8a Cleanup the go.mod files 2023-08-21 08:36:48 -04:00
RW
8a0fa4c063 🐛 [Bug-Fix]: add lock to avoid data race #2360 #2368
2e8ca17a76
2023-03-14 11:43:34 +01:00
Leon Klingele
117838fd0e memory: move costly operations outside of locked area 2022-11-14 03:20:20 +01:00
Leon Klingele
318b2fc04c memory: ensure to never delete non-expired items
This fixes a TOCTOU problem between a mutex rlock and a mutex lock.
2022-11-14 03:19:31 +01:00
Leon Klingele
0aa08303bc memory: cache timestamp 2022-11-14 03:18:42 +01:00
René Werner
c850eaff51 increase performance for the memory storage 2022-10-19 11:42:09 +02:00
Juan Calderon-Perez
3a8b8d4f71 Add Conn() support to all storage drivers. (#451)
* Add DB() support for Redis driver

* Added support for DB() to all drivers

* Fixed typo in README and Lint issue

* Fix lint issue with ristretto db

* Fix lint issue with bbolt db

* Rename DB() to Conn()

* Replace all instances of _DB with _Conn

* Update all the README files

* Return ArangoDB Client instead of DB
2022-08-15 07:58:13 +02:00
Fenny
ab94351a60 ✏ return nil for notfound 2020-11-23 09:30:50 +01:00
Fenny
fd56bd28da 🎭 stay backwards compatible 2020-11-18 09:00:59 +01:00
Fenny
ddef41c2ee ✏ update comments 2020-11-17 13:56:09 +01:00
Fenny
c57c524007 📦 add dynamodb 2020-11-12 20:14:21 +01:00
Fenny
cdf009407b 🩹 update tests 2020-11-06 16:05:53 +01:00
kiyon
5c5de159d0 🚤 Improve memory storage 2020-11-06 09:32:50 +08:00
Fenny
f9a30234b9 🧹 introduce reset and close 2020-11-06 01:41:46 +01:00
Fenny
86b9cfe4c1 remove close method 2020-11-05 06:08:05 +01:00
Fenny
5571999805 sql queries T.T 2020-11-05 06:01:59 +01:00
Fenny
8440b5e3c0 🎑 update tests 2020-11-05 05:36:27 +01:00
Fenny
92de7851b4 Update memory.go 2020-11-05 04:18:31 +01:00
Fenny
a6058cffb3 ✏ refactor storage 2020-11-04 20:49:53 +01:00
kiyon
2350adcae2 👷 Improve memory storage 2020-11-03 08:26:25 +08:00
Tom
23a3640cfb 📦 Fix expiration checks
Affects memory, postgres and sqlite3 drivers
2020-11-01 13:33:57 +00:00
Fenny
127aa2a67d 🎑 update sqlite3 2020-11-01 10:52:23 +01:00
Fenny
0692b9048e 🦴 update skeleton 2020-10-31 11:58:00 +01:00
Fenny
ef04d509b9 🩹 fix tests 2020-10-31 11:35:31 +01:00
Fenny
cc186961ee 👀 expose DB 2020-10-31 11:27:51 +01:00
Fenny
35ae11f248 🍡 fix gosec 2020-10-31 11:07:34 +01:00
Fenny
c14befe194 🎨 update memory storage 2020-10-31 10:16:11 +01:00
Tom
288df5384e [Memory] Add in-memory driver 2020-10-30 17:42:32 +00:00