Skip to content

[BUG] Adding new torrent via REST API with invalid body breaks web UI #569

@pursvir

Description

@pursvir

Bug description

Adding new torrent via POST request with invalid values for optional keys (except "link" value) in JSON body makes web UI turn into a white page, while browser console logs following errors:

asm.js type error: Asm.js optimizer disabled because debugger is active 2.86893fce.chunk.js

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
    Mi index.jsx:95
    React 10
    unstable_runWithPriority scheduler.production.min.js:18
    React 4
    flush notifyManager.js:75
    promise callback*E utils.js:322
    flush notifyManager.js:74
    batch notifyManager.js:30
    dispatch query.js:392
    setData query.js:85
    onSuccess query.js:336
    p retryer.js:58
    promise callback*l retryer.js:116
    c retryer.js:156
    fetch query.js:332
    executeFetch queryObserver.js:199
    onSubscribe queryObserver.js:40
    subscribe subscribable.js:16
    c useBaseQuery.js:60
    zu React
    unstable_runWithPriority scheduler.production.min.js:18
    React 3
    D scheduler.production.min.js:16
    onmessage scheduler.production.min.js:12
    EventHandlerNonNull* scheduler.production.min.js:12
    l (index):1
    <anonymous> index.js:4
    l (index):1
    <anonymous> React
    l (index):1
    <anonymous> React
    l (index):1
    444 main.c80cc924.chunk.js:1
    l (index):1
    t (index):1
    r (index):1
    <anonymous> main.c80cc924.chunk.js:1
react-dom.production.min.js:216:200

Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
    Mi index.jsx:95
    React 10
    unstable_runWithPriority scheduler.production.min.js:18
    React 4
    flush notifyManager.js:75
    promise callback*E utils.js:322
    flush notifyManager.js:74
    batch notifyManager.js:30
    dispatch query.js:392
    setData query.js:85
    onSuccess query.js:336
    p retryer.js:58
    promise callback*l retryer.js:116
    c retryer.js:156
    fetch query.js:332
    executeFetch queryObserver.js:199
    onSubscribe queryObserver.js:40
    subscribe subscribable.js:16
    c useBaseQuery.js:60
    zu React
    unstable_runWithPriority scheduler.production.min.js:18
    React 3
    D scheduler.production.min.js:16
    onmessage scheduler.production.min.js:12
    EventHandlerNonNull* scheduler.production.min.js:12
    l (index):1
    <anonymous> index.js:4
    l (index):1
    <anonymous> React
    l (index):1
    <anonymous> React
    l (index):1
    444 main.c80cc924.chunk.js:1
    l (index):1
    t (index):1
    r (index):1
    <anonymous> main.c80cc924.chunk.js:1
index.jsx:95:34

Torrserver logs:

=========== START ===========
TorrServer MatriX.136, go1.24.4, CPU Num: NO
2025/10/05 8:32:44 Check dns OK [NO NO] <nil>
2025/10/05 8:32:44 XPathDBRouter: Registered new DB "JsonDB", total 1 DBs registered
2025/10/05 8:32:44 XPathDBRouter: Registered new route "" for DB "JsonDB", total 1 routes
2025/10/05 8:32:44 XPathDBRouter: Registered new route "settings" for DB "JsonDB", total 2 routes
2025/10/05 8:32:44 XPathDBRouter: Registered new route "viewed" for DB "JsonDB", total 3 routes
2025/10/05 8:32:44 XPathDBRouter: Registered new DB "TDB", total 2 DBs registered
2025/10/05 8:32:44 XPathDBRouter: Registered new route "torrents" for DB "TDB", total 4 routes
2025/10/05 8:32:44 Check web port 8090
2025/10/05 8:32:44 Start TorrServer MatriX.136 torrent v1.2.22
2025/10/05 8:32:44 Local IPs: [192.168.1.25]
2025/10/05 8:32:44 Set listen port to random autoselect (0)
2025/10/05 8:32:44 Client config: {"CacheSize":67108864,"ReaderReadAHead":95,"PreloadCache":50,"UseDisk":false,"TorrentsSavePath":"","RemoveCacheOnDrop":false,"ForceEncrypt":false,"RetrackersMode":1,"TorrentDisconnectTimeout":30,"EnableDebug":false,"EnableDLNA":false,"FriendlyName":"","EnableRutorSearch":false,"EnableIPv6":false,"DisableTCP":false,"DisableUTP":false,"DisableUPNP":false,"DisableDHT":false,"DisablePEX":false,"DisableUpload":false,"DownloadRateLimit":0,"UploadRateLimit":0,"ConnectionsLimit":25,"PeersListenPort":0,"SslPort":0,"SslCert":"","SslKey":"","ResponsiveMode":false}
2025/10/05 8:32:44 PublicIp4: NO
2025/10/05 8:32:44 Start http server at :8090
[2025-10-05 8:32:54 +0300 NIL github.com/anacrolix/torrent client.go:321]
  msg="dht server on 0.0.0.0:36405 (node id d5bdff750e34f9e6470a39e4a5a9b419eed49ca1) completed bootstrap ({36 25})"
2025/10/05 8:33:47 add torrent magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent
2025/10/05 8:33:49 Create cache for: Big Buck Bunny dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c
2025/10/05 8:33:49 save to db: dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c
2025/10/05 8:33:49 Error check image: Get "string": unsupported protocol scheme ""
2025/10/05 8:34:20 Torrent close by timeout dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c
2025/10/05 8:34:20 Close cache for: dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c

Environment:

Program: TorrServer Matrix 136 (x86_64 binary from GitHub release)
Device: Desktop
OS: Linux

Steps to reproduce

{
  "action": "add",
  "category": "string",
  "data": "string",
  "hash": "string",
  "link": "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent",
  "poster": "string",
  "save_to_db": true,
  "title": "string"
}

The same goes to any HTTP client, here's the curl example:

curl -X 'POST' \
  'http://localhost:8090/torrents' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "action": "add",
  "category": "string",
  "data": "string",
  "hash": "string",
  "link": "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent",
  "poster": "string",
  "save_to_db": true,
  "title": "string"
}'

Overall, I've tried to paste random string values for keys "poster" and "category" (but in the case with "category" there are no logs about "unsupported protocol scheme" in TorrServer logs). The result is the same.
Only removing config.db from torrserver directory fixes this issue.

Expected behaviour: TorrServer should respond to requests similar to above ones with 400 (or even better, 422) status code and not crash web UI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions