fix: add column whitelist to queryTopN to prevent SQL injection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -292,6 +292,13 @@ func (s *SQLiteStore) GetTopIPs(ctx context.Context, limit int) ([]TopEntry, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SQLiteStore) queryTopN(ctx context.Context, column string, limit int) ([]TopEntry, error) {
|
func (s *SQLiteStore) queryTopN(ctx context.Context, column string, limit int) ([]TopEntry, error) {
|
||||||
|
switch column {
|
||||||
|
case "username", "password", "ip":
|
||||||
|
// valid columns
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid column: %s", column)
|
||||||
|
}
|
||||||
|
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
SELECT %s, SUM(count) AS total
|
SELECT %s, SUM(count) AS total
|
||||||
FROM login_attempts
|
FROM login_attempts
|
||||||
|
|||||||
Reference in New Issue
Block a user