Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Add validation for R2 key

Edward Cui2508d3280eaa
diff --git a/server/src/services/storage/r2StorageService.ts b/server/src/services/storage/r2StorageService.ts
index eaaf35628..97f05f264 100644
--- a/server/src/services/storage/r2StorageService.ts
+++ b/server/src/services/storage/r2StorageService.ts
@@ -249,6 +249,14 @@ class R2StorageService {
throw new Error("R2 storage is not enabled");
}
+ if (key.trim().length === 0) {
+ throw new Error("Invalid storage key: key cannot be empty");
+ }
+
+ if (key.includes("..")) {
+ throw new Error("Invalid storage key: path traversal not allowed");
+ }
+
try {
const response = await this.client.send(
new GetObjectCommand({