Repository navigation
Fixing the web API, ONVIF and RTSP issues from the November security reports - #103
Conversation
…sites - region_fill_formatted() appended every placeholder to out[80] with an unchecked strcat; with the default time format five $t already ran past it, and a full OSD text of them wrote a kilobyte onto the stack. Every append now goes through a bounded helper. Also: $B no longer spins when getifaddrs() fails, $C survives a missing /proc/stat and a negative reading, the OSD thread's copy of the text is terminated, and /api/time?fmt= no longer leaves the format unterminated. - unescape_uri() drops decoded control characters: settings are saved to divinus.yaml a line each, so a %0A in one (adc_device, say) wrote a section of the caller's choosing -- a stream: whose dest sent the video elsewhere. The decoder is rewritten without the undefined double *++src; '+' keeps its old meaning. - Every setting and command is a GET with parameters, which any page can send with the Basic credentials a browser holds. A request to /exit, or to /api/ with parameters, whose Sec-Fetch-Site, Origin or Referer names another site is now refused with 403. Clients that send none of these headers (scripts, NVRs) are unaffected, and parameterless reads stay open. tst/osd-expand (built with AddressSanitizer) and tst/unescape-uri cover the first two; both fail on the previous code.
GetSnapshotUri returned the web admin's user:password inside the snapshot URI, and GetStreamUri the RTSP credentials inside the stream URI. /onvif is answered before the web auth check and ONVIF auth defaults off, so anyone who could reach the web port got the admin password, which opens the whole /api. The URIs now carry no credentials; clients authenticate to them as they do with any other camera.
- SETUP's track= indexed trans[2] unchecked, and the Transport header of the same request wrote through it before auth was decided. Out of range is now a parse error, kept past the header lines that reset the parser. - A request missing its final CRLF made __read_line detach the connection, after which the request was still answered -- into a NULL FILE. A connection that went away mid-request is no longer dispatched. - A full connection pool used to end the RTSP thread, so 16 idle connections took RTSP down until restart. The extra client is refused instead. - A TCP client that stopped reading made __tcp_flush wait for ever on the encoder's path, freezing video for every viewer. It now waits about a second, then shuts the socket down for the RTSP thread to clean up.
PR Summary by QodoHarden web API, ONVIF, OSD, and RTSP security boundaries
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
- cross_site_request(): Sec-Fetch-Site: same-site no longer skips the Origin/Referer check -- another port on the camera's own address is the same site. Only same-origin and none are settled by Fetch Metadata. - The guard also covers /api/ requests with a body: /api/osd/N takes an image as a multipart POST with no query, which a form elsewhere can send. - __tcp_flush() gives up after a 1 s deadline instead of after ten idle waits in a row, so a client that reads a few bytes now and then can no longer hold the encoder path either. - __connection_list_add() now owns the fd on every failure: a full pool closes it there, a failed fdopen through __connection_reset. The caller's extra close() could hit a number another thread had just been given.
|
Addressed Qodo's review in da2d8f2. Re-checked on the hi3516ev300 board.
|
|
Thank you very much, those are some nice findings! |
Fixes GHSA-g3hw-cxmj-vrr2, GHSA-95p3-p37v-q53f and GHSA-w8hv-4jp5-3993. One commit per advisory.
Web API (g3hw)
region_fill_formatted()no longer writes pastout[80]. Also fixed nearby:$Bno longer spins whengetifaddrs()fails;$Csurvives a missing/proc/stat;/api/time?fmt=are now always terminated.unescape_uri()drops decoded control characters, so a%0Ain a setting can no longer add a section (e.g. astream:with a foreigndest) to the saveddivinus.yaml. It is rewritten without the undefined double*++src;+keeps its old meaning./exit, or to/api/with parameters, is refused with 403 when itsSec-Fetch-Site,OriginorReferernames another site. Scripts and NVRs that send none of these headers are unaffected, and parameterless reads stay open.ONVIF (95p3)
RTSP (w8hv)
track=is bounds-checked. The error now survives the header lines that reset the parser.vfprintf(NULL)crash and a double detach.Tests:
./test.sh --allpasses (8/8), including two new tests that both fail on master:tst/osd-expand, built with ASan: master reports astack-buffer-overflow, a 20-byte WRITE;tst/unescape-uri.Builds:
hisi-v4,hisi-v4aandstar6ebuild cleanly.Hardware: checked on a hi3516ev300 + IMX335 running OpenIPC ultimate, against this build. Two non-destructive checks were also run against the board's stock divinus as controls.
GetSnapshotUri/GetStreamUri, no ONVIF authhttp://admin:12345@…/image.jpg,rtsp://admin:12345@…/api/time?fmt=with a foreignOriginOrigin, or no headers/exit,/api/cmd?savefrom a foreign originadc_devicewith%0A-separated sections, then savestream:section, value kept on its own line$t$t$t$t$tSETUP track=1000/track=4294967295, with and without authThe crash cases were not run against the stock binary on hardware: they would have tripped its watchdog.