@@ -168,24 +168,25 @@ func SanitizeWhereClause(where string, tableName string, options ...*RequestOpti
168168 }
169169
170170 // Build a set of allowed table prefixes (main table + preloaded relations)
171+ // Keys are stored lowercase for case-insensitive matching
171172 allowedPrefixes := make (map [string ]bool )
172173 if tableName != "" {
173- allowedPrefixes [tableName ] = true
174+ allowedPrefixes [strings . ToLower ( tableName ) ] = true
174175 }
175176
176177 // Add preload relation names as allowed prefixes
177178 if len (options ) > 0 && options [0 ] != nil {
178179 for pi := range options [0 ].Preload {
179180 if options [0 ].Preload [pi ].Relation != "" {
180- allowedPrefixes [options [0 ].Preload [pi ].Relation ] = true
181+ allowedPrefixes [strings . ToLower ( options [0 ].Preload [pi ].Relation ) ] = true
181182 logger .Debug ("Added preload relation '%s' as allowed table prefix" , options [0 ].Preload [pi ].Relation )
182183 }
183184 }
184185
185186 // Add join aliases as allowed prefixes
186187 for _ , alias := range options [0 ].JoinAliases {
187188 if alias != "" {
188- allowedPrefixes [alias ] = true
189+ allowedPrefixes [strings . ToLower ( alias ) ] = true
189190 logger .Debug ("Added join alias '%s' as allowed table prefix" , alias )
190191 }
191192 }
@@ -217,8 +218,8 @@ func SanitizeWhereClause(where string, tableName string, options ...*RequestOpti
217218 currentPrefix , columnName := extractTableAndColumn (condToCheck )
218219
219220 if currentPrefix != "" && columnName != "" {
220- // Check if the prefix is allowed (main table or preload relation)
221- if ! allowedPrefixes [currentPrefix ] {
221+ // Check if the prefix is allowed (main table or preload relation) - case-insensitive
222+ if ! allowedPrefixes [strings . ToLower ( currentPrefix ) ] {
222223 // Prefix is not in the allowed list - only fix if it's a valid column in the main table
223224 if validColumns == nil || isValidColumn (columnName , validColumns ) {
224225 // Replace the incorrect prefix with the correct main table name
0 commit comments