Commit Graph
108 Commits
Author SHA1 Message Date
Jash 4110867003 fix: UrlWithCredentials encodes credentials and keeps existing userinfo refs #6695 2026-11-18 18:36:13 +05:30
Jash eb99545d6f fix: end a query string name at the ampersand and decode it refs #6598 2026-11-17 12:29:40 +05:30
Isaac Connor 2c6acb943b Merge pull request #6420 from AJ0070/fix-integration-urls
fix: go2rtc and RTSP2Web source URLs, backchannel and stream removal
2026-11-16 21:29:43 -05:00
Isaac Connor aac479c61d Merge pull request #5493 from AJ0070/4334-libjwt3
fix: build the libjwt backend against libjwt 3
2026-11-16 18:10:07 -05:00
Jash 89ab9d12e0 fix: keep the source scheme when adding credentials, apply go2rtc backchannel without User, remove all go2rtc streams refs #6419 2026-11-16 15:21:43 +05:30
Jash 32f6d08a61 fix: restore zm_utils.cpp emptied by the previous commit refs #4334 2026-11-11 09:35:50 +05:30
Jash 018f2c20a6 fix: read bytes as unsigned in Base64Encode so non-ASCII input stays in the table refs #4334 2026-11-11 09:28:40 +05:30
Jash c15eefbfdc fix: parse AV1 LEB128 sizes in 64 bits instead of shifting an int past its width, fixes #5484 2026-11-08 15:59:43 +05:30
Nic BoetandClaude Opus 5.5 281aa1d1d2 fix: stop logging camera credentials in the HTTP remote camera's debug lines
A Remote monitor on the HTTP protocol logs every request it sends to the
camera at debug level 2: with a user and password that includes
"Authorization: Basic <base64 of user:password>", and the path's query
string, which for many cameras carries user= and pwd=. When the camera
asks for Digest, Authenticator::computeDigestResponse() logged
"<user>:<realm>:<password>" in clear and the HA1 hash, which is all a
client needs to answer that realm's challenges.

Add request_for_log(), which passes the request target through
url_for_log() and replaces the value of Authorization and
Proxy-Authorization headers, and log the requests through it. Drop the
two Digest lines that held the password and HA1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:56 -05:00
Nic BoetandClaude Opus 5.5 d70ad4463b fix: mask all of a camera password that contains a raw @
remove_authentication() and mask_authentication() ended the userinfo at
the first '@' of the URL. ffmpeg and cameras split the authority at its
last '@', so a camera password with an unencoded '@' works, and
everything after its first '@' was left in the "masked" path that zmc
logs, at Error level when the camera cannot be opened (the Logs table
at default settings). An '@' in the path or query was also taken for
userinfo.

End the userinfo at the last '@' before the path, query or fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 c64612e884 fix: stop logging stream credentials in go2rtc, janus and rtsp2web
The go2rtc, Janus and RTSP2Web managers logged the stream URLs and the
request bodies they send: camera user:password@, the RTSP restream's
?auth= hash, ZM_JANUS_SECRET and the Janus stream pin. The Janus line
with ZM_JANUS_SECRET is a Warning, so it reaches the Logs table at the
default database log level whenever Janus is unreachable.

Log URLs through a new url_for_log() (no credentials, no query string),
the pin as a fingerprint, and the request bodies not at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:22 -05:00
Isaac ConnorandClaude Opus 5.5 0d6ebcd42c fix: accept ZM_GO2RTC_PATH with or without its /api suffix
go2rtc serves its API under /api, and its websocket at /api/ws. zmc
appends /streams to ZM_GO2RTC_PATH and the browser appends /ws, so the
setting only worked if it ended in /api. The natural value to enter is
the server address, http://host:1984, and with that zmc reached
/streams, which is go2rtc's RTSPtoWeb compatibility endpoint, so no
stream was ever registered, and the browser's /ws was a 404. Where
another player was available the failure went unnoticed.

Normalise the setting where URLs are built from it: a trailing slash is
dropped and /api is added unless the path already ends in it, which also
covers go2rtc behind a reverse proxy at a sub-path.

- Go2RTCApiEndpoint() in zm_utils, used by zmc's Go2RTCManager.
- go2rtcApiUrl() in skin.js, used by MonitorStream and the console
  thumbnail stream. It assigns the path once, since stripping the slash
  from a bare host's "/" and appending gave "//api", as the old
  pathname += '/ws' gave "//ws".
- The option's help says the suffix is optional.

Catch2 and node tests cover bare hosts, trailing slashes, an existing
/api, a proxy sub-path and credentials in the URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:34:04 -04:00
Isaac Connor 9f3f6c6770 fix: only trust X-Forwarded-For from configured proxies for auth hash IPs
With ZM_AUTH_HASH_IPS on, the client address bound into the auth hash was
taken from the left-most X-Forwarded-For value whenever the header was
present, both when PHP generated the hash (getRemoteAddr()) and when PHP or
zms validated it (getAuthUser(), zmLoadAuthUser()). The header is client
controlled, so anyone holding a leaked hash could replay it from anywhere by
sending the address it was bound to.

Add ZM_AUTH_TRUSTED_PROXIES, a list of exact reverse proxy addresses.
X-Forwarded-For is now used only when REMOTE_ADDR is one of them, and is read
from the right, skipping hops that are themselves listed proxies, so values a
client prepends are never chosen. With the option empty, the default, the
header is ignored and REMOTE_ADDR is used.

PHP (web/includes/Network.php getRemoteAddr()) and C++ (ClientAddress() in
zm_utils, used by zmLoadAuthUser()) implement the same rule so generation and
validation continue to agree. Every PHP caller already routes through
getRemoteAddr(), so session.php and auth.php need no change.

Reverse proxy users who enable ZM_AUTH_HASH_IPS must list their proxy in the
new option; until they do, hashes bind to the proxy address, which still
validates but no longer distinguishes clients. This is the behaviour change
that the #4921 work avoided by trusting the header.

The option is added through ConfigData only, like other recent options;
zmupdate.pl --freshen inserts it, zms falls back to the compiled-in default and
PHP treats an undefined constant as empty, so no schema migration is needed.

Tests: ClientAddress Catch2 case; tests/php/test_remote_addr.php updated for
the trusted-proxy rule.

refs GHSA-72rf-54rm-798c

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit acea5889dec0826f595cb736147a5fdc9c94a2a9)
2026-09-24 19:51:27 -04:00
Jash 1e7d8e1dd9 fix: cast tv_usec for %jd so armhf varargs stay aligned refs #4580 2026-08-26 11:23:11 +05:30
Jash bd3097be58 fix: escape JSON strings in a single pass so quotes are not double-escaped 2026-08-17 04:39:24 +05:30
Jash 3983db5357 fix: percent-encode non-ASCII bytes in UriEncode and escape go2rtc JSON fields 2026-08-16 15:37:21 +05:30
Isaac ConnorandClaude Opus 4.8 7cd4be5cfb feat: add nph-zms memory diagnostics refs #5006
Add instrumentation to trace which stream type and workload precede the
occasional runaway memory growth in nph-zms.

- zm_utils: add zm_get_rss_kb() reading resident set size from
  /proc/self/statm
- zms: log a one-shot Debug summary of the decoded request (source, mode,
  monitor/event, connkey, scale, buffer, ttl, rss) so a runaway process
  can be tied to its stream parameters
- MonitorStream/EventStream: emit a periodic Debug RSS trace every 30s.
  The EventStream trace includes frames-vector size and frame_count,
  which scale with reloaded event length and will show whether the
  in-process event reload path drives the growth

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 09:48:44 -04:00
Isaac Connor 334994bd3f Fix appending %% instead of % when uri decoding. Add test for URIEncode 2026-02-04 20:45:46 -05:00
Isaac Connor 548991ea3c Move escape_json_string and remove_newlines to zm_utils 2025-06-26 14:53:38 -04:00
Aaron Kling c4683d90a9 Format code using astyle google format
Commands used:
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.cpp
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.h
2024-03-26 13:43:58 -05:00
Alejandro Criado-Pérez 543683aa4c Corrections on cpp and h files 2023-08-13 01:27:19 +02:00
Isaac Connor a62f4b2e77 Use snprintf instead of sprintf to quieten codeql 2023-02-23 16:52:19 -05:00
Isaac Connor 594649605c Slightly smarted UriEncode, which doens't include numbers and a few other valid characters. Needs more work and tests. 2022-09-07 09:31:50 -04:00
parvit (Vittorio Parrella) a94d74143e support for ffmpeg type camera authentication with special characters 2022-08-20 10:01:14 -04:00
Isaac Connor 365830a9ae Rough in remove_password function + tests 2022-07-04 09:53:50 -04:00
Isaac Connor 8674b32a15 Introduce mask_authentication function to replace username and password with * in url like strings 2022-04-18 13:33:10 -04:00
Isaac Connor cb30f7639f revert broken commit. Isaac doesn't know what he's doing. 2022-01-10 18:47:26 -05:00
Isaac Connor 78a10b6095 cppcheck fixes 2022-01-10 17:36:49 -05:00
pkubaj 74a2276671 Fix build on FreeBSD/armv7
1. FreeBSD uses elf_aux_info instead of getauxval.
2. FreeBSD uses HWCAP_NEON macro for Neon.
2021-11-29 00:03:45 +00:00
Peter Keresztes Schmidt eaf2e51b0c utils: Make sure the compiler can emit format warnings for stringtf
Unfortunately the compilers can't emit Wformat warnings for variadic templates
and those can't be annotated with the format attribute.
Use a variadic function which can be annotated and thus warns on format string-args mismatches.

Ref 0796a2262e
2021-07-06 10:33:17 +02:00
Peter Keresztes Schmidt ff8c9f67c1 Image: Convert API to std::chrono
Utils: Remove TimespecDiff. It is not used anymore
2021-06-13 14:50:16 +02:00
Peter Keresztes Schmidt 46155942c1 Misc: Rename namespace ZM to zm
We had a mixture of both spellings. Unify it according to our code-style.
2021-06-06 19:11:11 +02:00
Peter Keresztes Schmidt d2932b5d68 Utils: Add a ByteArrayToHexString helper 2021-05-30 22:53:05 +02:00
Isaac Connor b37aa35085 improve scope of a,b 2021-04-20 17:07:07 -04:00
Peter Keresztes Schmidt e92125afd9 utils: remove unused curl include 2021-04-04 01:18:34 +02:00
Peter Keresztes Schmidt b5f3682d4e utils: some more reshuffling/grouping and formatting 2021-04-04 01:18:34 +02:00
Peter Keresztes Schmidt 545f0dbb96 utils: cleanup Base64Encode 2021-04-04 00:39:40 +02:00
Peter Keresztes Schmidt e330f8553d utils: cleanup Split and Join 2021-04-04 00:30:18 +02:00
Peter Keresztes Schmidt 39a896f5b6 utils: cleanup StartsWith 2021-04-03 23:51:12 +02:00
Peter Keresztes Schmidt 3dbf13e00b utils: cleanup ReplaceAll 2021-04-03 23:50:35 +02:00
Peter Keresztes Schmidt 664cd649f8 utils: cleanup Trim (was trimSet) and TrimSpaces 2021-04-03 23:30:59 +02:00
Isaac Connor 3f8b9db3d9 fix UriEncode returning a string that is longer than the c_str 2021-03-24 13:29:17 -04:00
Peter Keresztes Schmidt 7e86e1ef40 utils: Make TimevalToString thread-safe 2021-03-21 21:42:02 +01:00
Isaac Connor 5d968358f7 Need to use ZM::make_unique because std::make_unique is c++14 2021-03-10 16:35:03 -05:00
Isaac Connor 000df68f72 include memory 2021-03-10 16:17:26 -05:00
Isaac Connor aadee4ea65 add a Query String parse in zm_utils
add an authenticator to use with RtspServer
2021-03-10 13:20:14 -05:00
Peter Keresztes Schmidt 0796a2262e Utils: Replace stringtf with a type-safe version that can't overflow 2021-03-06 00:12:18 +01:00
Isaac Connor 8f783c0ec4 Must also include cstdarg for va_start etc al 2021-02-09 23:32:27 -05:00
Isaac Connor 9879a40c4b Must include cstring 2021-02-09 23:32:27 -05:00
Peter Keresztes Schmidt 0dbc39ee25 Cleanup and reorganize includes
With this commit a unified structure for includes is introduced.
The general rules:
 * Only include what you need
 * Include wherever possible in the cpp and forward-declare in the header

 The includes are sorted in a local to global fashion. This means for the include order:
  0. If cpp file: The corresponding h file and an empty line
  1. Includes from the project sorted alphabetically
  2. System/library includes sorted alphabetically
  3. Conditional includes
2021-02-04 18:02:01 +01:00