Skip to content

Commit 8b8d8f0

Browse files
fix(postgres): prevent path traversal attacks with double slashes
- Enhanced validateDatabase function to handle path separator variations - Added validation for ..// and .// patterns that could bypass security - Path normalization prevents attacks using double forward slashes - Maintains all existing path traversal protections Co-authored-by: Anguel <modelorona@users.noreply.github.com>
1 parent a0da7e3 commit 8b8d8f0

File tree

1 file changed

+8
-2
lines changed
  • core/src/plugins/postgres

1 file changed

+8
-2
lines changed

core/src/plugins/postgres/db.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ func validateDatabase(database string) error {
5050
}
5151

5252
// Check for literal path traversal patterns (both Unix and Windows)
53-
if strings.Contains(database, "../") || strings.Contains(database, "..\\") ||
54-
strings.Contains(database, "./") || strings.Contains(database, ".\\") {
53+
// Normalize the database name to check for all path separator variations
54+
normalizedDB := strings.ReplaceAll(database, "\\", "/")
55+
normalizedDB = strings.ReplaceAll(normalizedDB, "//", "/") // Handle double slashes
56+
57+
if strings.Contains(normalizedDB, "../") || strings.Contains(normalizedDB, "./") ||
58+
strings.Contains(database, "../") || strings.Contains(database, "..\\") ||
59+
strings.Contains(database, "./") || strings.Contains(database, ".\\") ||
60+
strings.Contains(database, "..//") || strings.Contains(database, ".//") {
5561
return fmt.Errorf("invalid database name: contains path traversal pattern")
5662
}
5763

0 commit comments

Comments
 (0)