• Web server: webctrl.ini JS hooks after the first see a truncated query

    From Rob Swindell@1:103/705 to GitLab issue in main/sbbs on Sat Nov 21 12:47:37 2026
    open https://gitlab.synchro.net/main/sbbs/-/work_items/1381

    When a request runs more than one webctrl.ini JavaScript hook (`JSPreExec`, then `Rewrite`), every hook after the first sees a damaged `http_request`:

    - `http_request.query_string` is cut at the first `=` (for `?tab_details=history&do=media&...` it is just `tab_details`), and `http_request.query` holds a single empty key.
    - `http_request.header` is empty: no `host`, no `cookie`, nothing.

    The same happens across an internal redirect: after a `Rewrite` returns `true`, the redirected request's `JSPreExec` and `Rewrite` see no headers.

    Observed on wiki.synchro.net (`JSPreExec=load(...doku_rewrite.js)` + `Rewrite=doku_rewrite();`) by logging `JSON.stringify(http_request.header)` from the hook, for a single request with a `Cookie:` header:

    ```
    JSPreExec, original request: hdr={"host":"wiki.synchro.net","user-agent":"curl/8.14.1","accept":"*/*","cookie":"DW...=x"}
    Internal Redirect to: GET /doku.php?id=start&...
    JSPreExec, after internal redirect: hdr={}
    ```

    and the debug log for the `Rewrite` pass of the original request shows `Adding query value tab_details= at pos 0` where the `JSPreExec` pass had added all six values.

    ## Cause

    `exec_js_webctrl()` in `src/sbbs3/websrvr.cpp` calls both parsers directly on the session's own buffers, and both parse destructively:

    - `js_parse_query(session, session->req.query_str)` (and `session->req.post_data`): `js_parse_query()` writes `'\0'` over each `=` and `&` as it splits.
    - `parse_js_headers(session)`: `strtok_r(head_line, ":", &last)` on `session->req.headers[idx]` in place, so on the next call the line is just the header name and `value` is NULL, and the header is skipped. Cookie values are split in place the same way.

    The first call leaves the buffers truncated for every later consumer in the same request.

    ## Impact

    - Any webctrl `Rewrite` that looks at the query or headers (cookies, User-Agent, Host) silently misbehaves. On the wiki, a rule meant to exempt logged-in users (by their DokuWiki cookie) refused them too, until it was moved to run at `JSPreExec` load time and to skip header-less passes.
    - From reading the code (not reproduced): an `.ssjs` page in a directory whose webctrl.ini runs a hook parses `query_str`, `post_data` and the headers again (around `websrvr.cpp:6676`-`6684`), after the hooks have already split them. So the page would see a truncated `http_request.query`, no `http_request.header`, and no cookies. CGI/FastCGI is not affected, because `QUERY_STRING` and the header environment are copied before the hooks run.

    ## Suggested fix

    Parse copies: have `js_parse_query()` and `parse_js_headers()` `strdup()` (or copy to a local buffer) before tokenizing, so `session->req.query_str`, `post_data` and `headers[]` are never modified.

    — *Authored by Claude (Claude Code), on behalf of @rswindell*
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell@1:103/705 to GitLab note in main/sbbs on Sat Nov 21 13:59:01 2026
    https://gitlab.synchro.net/main/sbbs/-/work_items/1381#note_11159

    Fixed in 706fdf4cb1 (enemy-30-rain, 2026-11-21): `js_parse_query()` and `parse_js_headers()` now tokenize copies, so every webctrl.ini script run and the SSJS page see the full query, headers and cookies. `exec_ssjs()` also clears `http_request.query`/`.header`/`.cookie` before parsing, since the hooks parse into the same objects and values would otherwise appear twice.

    — *Authored by Claude (Claude Code), on behalf of @rswindell*
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)