Commit Graph
118 Commits
Author SHA1 Message Date
Isaac ConnorandClaude Opus 5.5 e8298d91cb fix: leave out deleted monitors' events in the events query, not after paging refs #5417
The Events list hid events of soft-deleted monitors (Monitors.Deleted) while
building the rows, after the filter limit, the page slice and the totals. Pages
came up short, the footer counted and summed events that were never listed,
and a filter limit counted hidden events too.

Exclude M.Deleted in both SELECTs of queryRequest() so the limit, paging and
totals only see listed events, and drop the per-row skip. The new test runs
queryRequest() against the database inside a rolled-back transaction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 17:19:32 -05:00
Nic BoetandClaude Opus 5.5 d4655c1137 fix(api): accept a bare monitor filter field that one joined table has
qualifyFields() required a bare field to be a Monitors column, so names
only a joined table has, such as Status, CaptureFPS and AnalysisFPS from
Monitor_Status, answered 400 where they used to filter:

  GET /api/monitors/index/Status:Connected.json   -> 400 Unknown filter field

A bare field that Monitors has is still written Monitor.Field. Otherwise
it must be a column of exactly one joined table and is left bare, as
before, for MySQL to resolve; buildFilter() does not accept an alias with
an underscore such as Monitor_Status, so it cannot be qualified. A bare
field no table has stays a 400, and one two joined tables have and
Monitors does not (MonitorId, in Monitor_Status and Event_Summaries) is a
400 "Ambiguous filter field" instead of a 500 from MySQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 11:31:26 -05:00
Nic BoetandClaude Opus 5.5 7fffa186f6 fix(api): check monitor filter fields, qualify them with the model
MonitorsController::index() passed its named parameters to
FilterComponent::buildFilter() without a field list, so any name made
of letters, digits and dots reached MySQL as a column:

  GET /api/monitors/index/Nope:1.json   -> 500, PDOException 42S22

and the bare names Id and Name, which the joined Manufacturers and
Models tables have too, failed as ambiguous columns (also 500).

FilterComponent::qualifyFields() checks each field against the columns
of the queried model and of the models find() joins, and writes it
Model.Field: a bare field is a Monitors column. GroupId stays bare for
the Groups_Monitors join. Anything else is a 400 "Unknown filter field",
as events/index answers since 028ccecb5. Column names match without
regard to case and are written as the schema spells them.

The web UI's map (Deleted:0) keeps working;
Name:x, Id >:0, Name LIKE:x and Id IN:1,2 now return monitors instead
of a 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 11:31:26 -05:00
Nic BoetandClaude Opus 5.5 66a1267b42 fix(api): keep exception text and credentials out of 5xx bodies
With debug 0, Cake replaces a 500's message with a generic one, but
Crud's exception renderer adds data.exception.message from the raw
exception. A PDOException (e.g. monitors/index/<unknown column>:1.json)
returned the SQL error and its fragment of the query to the client.
data.url also echoed the request URL with its token or password.

ZmExceptionRenderer extends Crud's renderer: with debug 0 a 5xx body
carries the generic message in data.exception.message (class and code
are kept), and data.url has credential values redacted.
AppController::beforeFilter() swaps it in for the renderer Crud's
ApiListener registers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 11:31:26 -05:00
Nic Boet c687bddf5a test: stub logFingerprint() for getAuthUser() in the auth hash compare test
getAuthUser() logs a fingerprint of the auth hash instead of the hash
(ZM\logFingerprint() from log_redact.php). The test evaluates
getAuthUser() in its own namespace with stub loggers, so it needs that
function stubbed too.
2026-11-01 10:28:15 -05:00
Nic BoetandClaude Opus 5.5 767bb4759e fix: redact object properties and SQL values in web log lines
ZM_Object::apply_defaults() logged every property of each object it
loaded at Debug level, so loading a Monitor wrote its Pass,
ONVIF_Password and the user:password@ in Path and ControlAddress, and
loading a User its password hash (found by the camera probe, after the
monitor-save fix). A statement that failed logged its bound values at
Error level, which reaches the Logs table: for a monitor or user save,
the camera password or the password hash. dbFetchOne()'s missing-column
warning printed the whole row.

Properties and rows go through redactForLog() (by field name). Bound
values of a failed statement are logged only with ZM_DB_DEBUG, the
setting that already logs every statement's values; otherwise their
count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 49ab7682ea fix: keep the auth relay out of PHP warnings on failed remote requests
When the other server of a multi-server install did not answer,
file_get_contents() raised a PHP warning whose text is the call and its
URL, ?auth=<hash> or user=/pass= included, and PHP wrote it to the web
server's error log (Event.php, Filter.php). The same happened with the
image proxy's digest retry (camera user:password@) and the X-Frame
check of a website monitor (get_headers()), which also took the false
it returns on failure for an array.

Fetch with @ and log lastErrorForLog(), the reason without the call
and its URL, next to urlForLog() of the URL. Server::SendToApi()
already used @ and now logs the reason too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 5c69921e18 fix: stop logging camera credentials in the web UI
The network probe logged the camera password it was about to try and
camera URLs with user:password@ (monitor_probe.php), saving a monitor
dumped the changed fields with Pass, ONVIF_Password and the Path and
ControlAddress credentials (actions/monitor.php), the ONVIF probe logged
the failing zmonvif-probe command line, password included, at Error
level, which reaches the Logs table by default (onvifprobe.php), the CSV
camera import logged each URL at Info level (add_monitors.php), and the
image proxy logged its Digest Authorization header and the camera URL
(views/image.php).

Log user names without passwords, URLs through urlForLog() and dumps
through redactForLog(). removeUserinfo(), used by both, now also strips
a ControlAddress's scheme-less user:password@host, and ends the userinfo
at the last @ before the path: a camera password with a raw @ in it
works with cameras and ffmpeg, and its tail was left in the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 8ccece3ad5 fix: keep the other query parameters in logged multi-server URLs
urlForLog() dropped the whole query string, which also hid the
parameters that say what the call was (view=, action=, user=). Run the
query through redactQueryString() instead: the auth relay's password is
replaced, auth= and token= become fingerprints, the rest is kept.
redactQueryString() now also ends a value at '?', since Event.php
builds the plain relay as ?user=..?pass=...

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 cffa439c31 fix: redact credentials from the login redirect in the debug log
An unauthenticated request is redirected to the login view with its
query string in postLoginQuery, and index.php logged that redirect at
debug level: an expired or refused auth= hash, a token= JWT or a
password= sent in the URL went into the log twice, once in the
"Redirecting to" line and once in the next request's parameter dump.

redactForLog() now also redacts query strings found inside values, and
the redirect line goes through the new redactQueryString().

Found by the web probe on the fix branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 b9e20c84a4 fix: stop logging the auth relay in multi-server request URLs
Event.php, Server.php and Filter.php call the API or index.php of
another server with the auth relay appended (?auth=<hash>, or with
ZM_AUTH_RELAY=plain the user's username and password) and logged that
URL, at debug level before the call and at Error level when the other
server did not answer. Error reaches the Logs table at the default
database log level. Log it through urlForLog(), without the query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 f681c23825 fix: log a fingerprint of the auth hash in getAuthUser()
getAuthUser() logged the presented auth hash at debug level on every
check and at Info level whenever a check failed. Info reaches the Logs
table at the default database log level, which System=View users read.
A hash refused here can still be valid: bound to another client address
(ZM_AUTH_HASH_IPS) or meant for another server. Log its fingerprint,
the same tag zms and zm_rtsp_server log for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 afc10b52a9 fix: redact credentials from the request and session debug dumps
index.php logged print_r($_REQUEST) at debug level on every request:
the login form's password in clear, auth= hashes, token= JWTs, a new
user's password from the user form and camera passwords from the
monitor form. The API's AppController logged print_r($_SESSION) on
every cookie-authenticated call: the session's auth hashes and, with
ZM_AUTH_RELAY=plain, the user's password.

Add web/includes/log_redact.php (loaded by logger.php) with
redactForLog(), which keeps the dump's shape but replaces passwords and
secrets, fingerprints tokens, auth hashes and CSRF tokens, and strips
user:password@ from URL values; urlForLog(); and logFingerprint(), the
web side of zm::crypto::LogFingerprint().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:39 -05:00
Nic BoetandClaude Opus 5.5 06b7a43b2b fix: stop logging the encoded password and bcrypt hash at login
For a user whose hash zmupdate.pl overlaid with bcrypt ("-ZM-" prefix),
validateUser() logged the MySQL-encoded form of the typed password next
to the stored bcrypt hash at debug level, on every login attempt, right
or wrong. The MySQL-encoded form is SHA1(SHA1(password)), unsalted, so
it falls to an offline dictionary attack. The line above it already
says which comparison runs.

Adds tests/php/test_auth_log_redaction.php, which records every log line
validateUser() writes for each stored hash type and searches them for
the password, its encoded form and the stored hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:27:22 -05:00
Nic BoetandClaude Opus 5.5 b4d62a3d7f fix: escape the attributes buildMenuItem() writes
buildMenuItem() renders every left-sidebar menu entry and put $id,
$href and the link class into HTML attributes as given, so each caller
had to escape them; the Montage Review link did not. Escape them in
buildMenuItem() itself. Entities already in a value are kept, so the
callers that escape first (the Cycle link's &amp;, custom menu links,
the Montage Review link) render as before.

The links from ZM_WEB_NAVBAR_LINKS, which the sidebar reads back
through DOMDocument (decoded), are now re-encoded too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 23:01:19 -04:00
Nic BoetandClaude Opus 5.5 4a905c634a fix: escape filter times in the Montage Review navbar link
getMontageReviewHTML() copied the StartDateTime >= / <= values of
filter[Query][terms] into the link's href as they came in the request.
A value with a double quote closed the attribute, so a crafted link put
arbitrary markup into the navbar of any page it opened; an & added or
overrode query parameters of the link.

URL-encode minTime and maxTime, HTML-escape the whole href, and skip
terms that are not arrays or have a non-string value instead of
failing with a TypeError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 23:01:19 -04:00
Isaac Connor cf7a20681b Merge pull request #5405 from connortechnology/fix/ghsa-fqf5-options-api-system-edit
fix: require System edit to change API access or revoke tokens (GHSA-fqf5-vjpq-33gc)
2026-10-31 21:57:02 -04:00
Nic Boet 4571649d8e fix(web): disable the API tab's per-user checkboxes without System edit
The Update and Revoke All Tokens buttons are disabled for users without
System edit since the handlers refuse them; the Revoke Token and API
Enabled checkboxes next to each user stayed clickable and did nothing.
Disable them the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f096e919c2)
2026-10-31 20:02:16 -04:00
Nic Boet 56996ad3f1 fix: require System edit to change API access or revoke tokens
The API tab of Options renders for any user with System view, and the
view itself handled its two POST buttons: updateSelected sets
Users.APIEnabled for every user and revokeAllTokens bumps every user's
TokenMinExpiry. includes/actions/options.php refuses a System=View user,
but returns before the view is rendered, so the view went on and ran
the UPDATEs. A System=View user could turn off API access for every
account, admins included, and invalidate every issued token.

Run both handlers only when canEdit('System'), log a warning otherwise,
and disable the two buttons for users who cannot use them.
tests/php/test_options_api_requires_system_edit.php includes the view
with System=View and System=Edit and checks which SQL it sends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 6e64739e84)
2026-10-31 20:02:16 -04:00
Isaac Connor cd6e262dc5 Merge pull request #5402 from connortechnology/fix/ghsa-3m5x-events-view-acl
fix: API events/view refuses events on monitors the user may not view (GHSA-3m5x-32ch-gg29)
2026-10-31 19:53:10 -04:00
Nic Boet 97216d3d5a test: give the Event::canView() test user canView() and canEdit()
Event::canView() and canEdit() may ask the user for the permission
($u->canView('Events')) instead of reading the field, which counts a
role as well. The test's stub user only had the field getters, so such
an Event.php ends in a fatal error. The stub answers as User::canView()
and canEdit() do for a user without a role; the field getters stay for
the current Event.php.

(cherry picked from commit ea741802dd)
2026-10-31 19:08:28 -04:00
Nic Boet 184d33cd36 fix: refuse canView and canEdit for an Event with no Id
ZM\Event::canView() and canEdit() asked the event's Monitor, and an
Event with no MonitorId (built from an empty or failed lookup) gets an
empty Monitor, whose canView() falls back to the user's global Monitors
permission. So an Event with no Id passed both checks for any user with
Events access, whatever monitors they were denied. A caller that built
an Event from a lookup that could come back empty and trusted canView()
without checking Id() first failed open; the API's events/view did.

Return false from both when the Event has no Id. Every caller in the
web UI, ajax and API either checks Id() first or builds the Event from
a database row, so none relied on the empty Event passing; callers that
did not check (the frame view, export and download lists) now refuse a
missing event id instead of working on an empty one.

Test: tests/php/test_event_can_view_no_id.php drives the real ZM\Event
with a stub Monitor (8 of 13 checks fail before this change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 054d4f0fa6)
2026-10-31 19:08:08 -04:00
Nic Boet 7a64e50618 fix(api): refuse events/view for an event on a monitor the user may not view
EventsController::view() looks the event up with the per-monitor
condition and then asks ZM\Event::canView(). For an event on a denied
monitor the restricted find() is empty, the empty ZM\Event has no
monitor, and canView() falls back to the user's global Monitors
permission, so it passes. The action then answered 200 with a stub
built from the id alone: the hidden event's Next/Prev ids, its max
score and alarm frame ids, fileSize and a FileSystemPath.

The event is known to exist at that point, so an empty result means
the monitor condition removed it: answer 401 as edit, delete and
archive do.

Test: tests/php/test_api_event_view_acl.php (2 of 6 checks fail
without the fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit cf62c05576)
2026-10-31 19:08:08 -04:00
Isaac Connor 0f7bb088dc Merge commit from fork
fix(api): check the group, snapshot and tag links an edit will save (GHSA-6h3c-f3p7-pq4v)
2026-10-31 19:06:37 -04:00
Isaac Connor ab259c7495 Merge pull request #5399 from connortechnology/fix/ghsa-6h3c-api-associated-ids
fix: API group, snapshot and tag edits check the links they save (GHSA-6h3c-f3p7-pq4v)
2026-10-31 19:05:16 -04:00
Nic Boet 48a11c1bb7 fix: snapshot and tag edits keep the event links the editor can't view
An edit replaces all of a snapshot's or tag's event links, but only the
new list was checked, so {"Event": []} from a user denied a monitor
unlinked that monitor's events, and any list without them dropped them.
The API's view of a snapshot or tag leaves those events out, so a client
that reads the list, changes it and saves it dropped them too.

The new list still needs view on every event it links. The links to
events the user may not view are now added back to the list before the
save (eventLinksToSave()), so the user can change the links they see and
the others stay. A link to an event that no longer exists is dropped.

Test: tests/php/test_api_associated_ids.php
(cherry picked from commit 6b1d0eaf8d)
2026-10-31 18:45:52 -04:00
Nic Boet 959b47f67d fix: check the group and event links an API save will write
Groups, Snapshots and Tags add/edit checked the ids from MonitorIds or
EventIds when the request had them, but Model::save() links the HABTM
entry (Monitor, Event) and ignores those fields on edit. A Groups=Edit
user could send {"Group":{"MonitorIds":"<current members>"},"Monitor":[]}:
the membership check saw no monitor moved, the save emptied the group and
lifted the Groups_Permissions deny on its monitors. On add, an empty
MonitorIds or EventIds next to a Monitor/Event list let monitors the user
may not edit into a new group, and events the user may not view into a
snapshot.

requestAssociatedIds() now reads the list the way save() does and
rewrites the request's entry to that plain list of ids, so a row given as
a join record links only its MonitorId/EventId. add() copies MonitorIds
or EventIds into the entry before the check, as it did before the save.

Test: tests/php/test_api_associated_ids.php
(cherry picked from commit 6bf015530e)
2026-10-31 18:45:52 -04:00
Isaac Connor 077ffce1a1 Merge commit from fork
fix: make event videos only for events the user can view (GHSA-rmf7-q643-w8vm)
2026-10-31 18:42:59 -04:00
Nic Boet 5b8e7a0ad5 fix: make event videos only for events the user can view
ajax/event.php action=video appended monitorLimitSql() after GROUP BY,
where "GROUP BY E.Id AND MonitorId IN (...)" only changes the grouping
and filters nothing. A user denied a monitor could still have
zmvideo.pl encode that monitor's events and learn the file's path.

Put the limit in the WHERE clause and also check the loaded event with
Event::canView(), which applies the monitor's permission and the
Snapshots rule. monitorLimitSql() has no other caller.

tests/php/test_event_video_requires_view.php covers a denied monitor, a
missing event, a Snapshots-only user and a user without Events or
Snapshots view; 5 of its 11 checks fail before this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c95d4decbc)
2026-10-31 18:19:41 -04:00
Isaac Connor 55248b88f7 Merge pull request #5391 from connortechnology/fix/ghsa-7hhq-stream-owner
fix: name zms command sockets after the user the stream serves (GHSA-7hhq)
2026-10-31 17:04:34 -04:00
Nic BoetandClaude Opus 4.8 1d6dcff83b fix: name zms command sockets after the user the stream serves refs GHSA-7hhq-xw65-4crf
ajax/stream.php sends stream commands (query, pause, seek, zoom, quit)
to the zms whose unix socket matches a connkey, with no permission
check. Connkeys are six random digits chosen when the stream starts,
so any logged-in user who guessed or saw one could read the status of
another user's stream, of a monitor they may not view included, and
pause or end it. A second zms started with the same connkey also waited
on the first one's lock and then took over its socket.

zms already authenticates the user and checks their access to the
monitor or event before it streams. Keep that user's id and put it in
the lock, command socket and reply socket names
(zms-<connkey>-<user id>s.sock); stream.php builds the names from the
caller's own id through zmsSocketPath(), so a request reaches only the
caller's streams. Without authentication the id is 0 on both sides.

Adds a StreamBase test in tests/zm_stream.cpp and
tests/php/test_zms_socket_path.php, which pin the same names. The
existing command-socket-teardown test is updated for the owner-suffixed
names (it postdates the reporter's base commit).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-31 11:11:01 -04:00
Isaac Connor 0ad172d989 Merge pull request #5387 from connortechnology/fix/ghsa-qrhf-login-token
fix: refuse host/login with both a password and a token (GHSA-qrhf)
2026-10-31 10:59:17 -04:00
Nic Boet 60880b1c91 fix: refuse host/login with both a password and a token
beforeFilter() authenticates user=/pass= (or username=/password=) and
then a token=, keeping the token's user. login() mints a refresh token
for that user whenever a password was sent, so a caller's own password
plus another user's refresh token gave a new 24 h refresh token for the
other user, renewing a token that is otherwise never renewed. A login now
takes one or the other. refs GHSA-m77q-66v7-j3fq

Test: tests/php/test_api_login_token.php
(cherry picked from commit 4223c12dad28b1ff1ff8738a6709bae6dc74f1bd)
2026-10-31 10:46:05 -04:00
Isaac Connor ac1e167e6e Merge pull request #5382 from connortechnology/fix/ghsa-2pgc-session-fixation
fix: reject client-chosen session ids and regenerate on auth= / stateful API login (GHSA-2pgc)
2026-10-31 09:34:50 -04:00
Nic Boet 70b3847b8c fix: reject session ids the server never issued
zm_session_start() sets session.use_strict_mode, but PHP asks a user
session handler whether an id exists only through
SessionUpdateTimestampHandlerInterface::validateId(). ZMSessionHandler
implemented only SessionHandlerInterface, so strict mode did nothing:
any ZMSESSID a client sent became its session id and was stored. That
let a session id be planted in a victim's browser and used after they
logged in (session fixation).

Implement the interface: validateId() checks for the Sessions row, so
PHP replaces an unknown id; updateTimestamp() writes as write() does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 11b3883e6a)
2026-10-31 09:04:37 -04:00
Isaac Connor daf4fcbfda Merge pull request #5379 from connortechnology/3qq8-zmu-token
fix: give zmu a short-lived token instead of reusable credentials (GHSA-3qq8-fq8j-rx7j)
2026-10-30 23:59:22 -04:00
Nic Boet 46ccb7529f fix: without a token secret, zmu still gets an API request's own password
When ZM_AUTH_HASH_SECRET is unusable zmu refuses tokens, so
zmuCredentials() falls back to what zmu got before. With
ZM_AUTH_RELAY=plain the API's alarm action used to pass the password
from the request (pass= or password=); the fallback read only the
session, which an API call without a stateful login doesn't have, so
zmu refused the call (rc 255). zmuCredentials() takes the caller's
password first again. With a usable secret it is never used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5ca19c2703ea9211fe040991305ce9b0a873faff)
2026-10-30 19:30:28 -04:00
Nic Boet 35e36e4dda fix: give zmu a short-lived token instead of the password or auth hash
getZmuCommand() and the API's alarm action put the user's credentials on
zmu's command line, where every local user can read them (ps,
/proc/<pid>/cmdline): an auth hash with the default hashed relay, the
plaintext password with ZM_AUTH_RELAY=plain. The API also wrote the
whole command to the debug log. With the default ZM_AUTH_HASH_IPS=0 that
hash is accepted as an auth= login from any address for ZM_AUTH_HASH_TTL
hours.

zmuCredentials() builds them in one place: with a usable
ZM_AUTH_HASH_SECRET, an access token for the user that expires after a
minute (zmu -T, accepted with every relay). Without the secret zmu
refuses tokens, so it gets what it did before. The API logs the command
without the credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 32bc2b3fee87b752590ba6f210403afd9222d9ff)
2026-10-30 19:30:27 -04:00
Nic Boet 8359958068 fix(api): redact credentials sent as arrays, keep empty values visible
ZmErrorHandler::redact() matched token=, auth=, pass= and password=
only. A client that sends one of them as an array (token[]=x, which
Cake logs as token%5B0%5D=x) still puts the value in the log, so the
name may now carry [..] or %5B..%5D before the =.

An empty value is no longer replaced: token= stays token=, so the log
still shows a client that sent no credential.

Tests: prefixes (authority, tokenize, password2, pass_hint, token_type,
passwd) are not touched, arrays are redacted, empty stays empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4789df0a04)
2026-10-30 18:53:27 -04:00
Nic Boet 91b06f6d02 fix(api): keep credentials out of cake_error.log
Cake logs every uncaught exception, 4xx included, with "Request URL:"
and the full query string. API clients may authenticate with ?token=,
?auth= or ?user=&pass=, so a 401, 404 or 500 wrote a working access
token, auth hash or password to cake_error.log and error.log in
ZM_LOGDIR, both world-readable.

ZmErrorHandler extends Cake's ErrorHandler and replaces the values of
token, auth, pass and password with [redacted] in the logged message.
core.php uses it for both errors and exceptions.

Credentials in the query string still reach web server and proxy
access logs; that is outside the API code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b80568847d)
2026-10-30 18:53:27 -04:00
Nic Boet 052efeb90d fix: require Snapshots edit to create a snapshot
The snapshot action's create step had no permission check: any
logged-in user could POST view=snapshot&action=create and have the
server force an alarm (zmu -a) on any monitor id, record an event and
archive it, and add a Snapshots row. zmu itself only asks for Stream
view on a monitor it can access, so a stock viewer forced alarms; a
user without Stream still added Snapshots rows.

Create now needs Snapshots edit, uses only monitors the user can view,
and creates nothing when none is left. An unknown or non-numeric
monitor id used to call Error(), which is PHP's Error class, not a
function, and ended the request with a fatal error; it is now logged
with ZM\Error and skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 910961d744b26da577f393ec17ef084ddcb474a5)
2026-10-30 18:11:04 -04:00
Nic Boet 012063d3e1 fix: change or delete only events on monitors the user can view
The ajax/event.php actions rename, eventdetail, archive, unarchive and
delete checked Events edit only, and took any event id: a user with
Events edit restricted to some monitors could rename, annotate,
archive, unarchive or delete events of monitors they can't see. The
web event action and the API already check the event's monitor.

Load the event once for every Edit-level action in ajax/event.php and
require visibleMonitor() on its monitor, as addtag/removetag do; a
missing and a hidden event get the same answer (delete keeps its "Event
not found." reply). getselectedtags lists no tags of an event on a
hidden monitor.

includes/actions/eventdetail.php checks each event's monitor since
13138a0af, but passes markEids entries through validInt(), which keeps
an array an array, and new ZM\Event() takes an array as the row itself
without loading it: markEids[0][Id]=<hidden event>&markEids[0][MonitorId]=
<visible monitor> passes canEdit() and updates the hidden event. Take
only scalar ids there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit afe6452e421b10a9738d243bb5092cbbb2c4d0a6)
2026-10-30 18:10:30 -04:00
Nic Boet 9428d2cdf0 fix(web): require Control edit for camera settings, store only what zmu set
includes/actions/settings.php ran for Control view, while the settings
modal only enables its sliders with Control edit. zmu itself refuses
users without Monitors edit and then prints nothing; the action still
wrote that output into Monitors (Brightness, Contrast, Hue, Colour),
which strict SQL mode rejects with an error and a non-strict server
would store as 0.

Require Control edit (with the monitor checked by canView, since
canEdit('Control', $mid) also demands Monitors edit), and update
Monitors only when zmu reports four integers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 49247d3bf89a78aeef3624bb33827d0b93e4a9b6)
2026-10-30 18:10:07 -04:00
Nic Boet 321796dc4e fix(web): let Events view users delete the videos they generate
The video view generates videos (Events view, ajax/event.php action
video) and lists them under Existing Video Files with a Delete link.
Requiring Events edit for every delete also took that from viewers,
although only the event's recording needs protecting: a generated
video can be made again from it.

Treat as the recording the event's DefaultVideo, incomplete.<ext> (zmc's
name while recording) and <Id>-video.* (its final name), and require
Events edit for those only. Show the Delete link per file by the same
rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a7c4b01a254bf006eec40cf1c9aa8bc82c92e6f3)
2026-10-30 18:10:07 -04:00
Nic Boet 123b36d43c fix(web): video view links address the file in their row
The file list numbered its rows with a counter that skipped empty
files, while deleteIndex, downloadIndex and showIndex look the number up
as the key in $videoFiles. With an empty file earlier in the directory
(for example a video generation that failed) every later row's Download,
Show and Delete acted on another file, Delete included. Use the array
key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ca1b9311edab1a6eca6d61864a0e03f2796f3b77)
2026-10-30 18:10:07 -04:00
Nic Boet 7f09a39c88 fix: tag only events on monitors the user can view
addtag and removetag took any event id: a user with Events edit
restricted to some monitors could tag or untag events on monitors they
can't see. Filters select events by tag (a purge filter can keep tagged
events, or delete them), so that reaches events the user has no access
to. Load the event and require visibleMonitor() on its monitor; a
missing and a hidden event get the same error. removetag now validates
its ids like addtag.

ajax/tags.php listed tags only for Events view since the previous
commit, but the event view also serves Snapshots view users and loads
the tag list; accept either, as ajax/event.php does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5b9df458d55d3491086dbbe25dbac2d3f3db1264)
2026-10-30 18:10:07 -04:00
Nic Boet 7bae8d61bb fix: require Events edit to tag events or delete event videos
Three event write paths were reachable with Events view only:

- ajax/event.php handled addtag and removetag in its canView('Events')
  block. removetag also deletes the Tag row once no event uses it.
- ajax/tags.php had no permission check, so createtag inserted Tags for
  any logged-in user, and getavailabletags listed them.
- views/video.php opens with canView('Events') and unlinks
  $videoFiles[deleteIndex]. ZM_FFMPEG_FORMATS defaults to "mp4* ...", so
  that list includes the event's own recording: a viewer could delete
  the recorded video of every event on the monitors they can see.

Move addtag and removetag into the canEdit('Events') block next to
rename and archive. In tags.php require canView('Events') for the file
and canEdit('Events') for createtag. In video.php require
canEdit('Events') for deleteIndex, skip indexes that are not in the
list, and only show the Delete link to users who can use it. The event
view disables the tag input and the tag-and-step buttons for users
without Events edit.

tests/php/test_event_writes_require_events_edit.php drives the three
files with Events None, View and Edit and checks the SQL they send and
whether the video file survives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d935293c527c4543a3afbdad1afdddc774c63ea2)
2026-10-30 18:10:07 -04:00
Isaac Connor 2e50bdc431 Merge pull request #5360 from connortechnology/8g63-config-secret-oracle
fix: stop the Config API leaking secret values (GHSA-8g63-hqg8-82cv)
2026-10-30 08:51:27 -04:00
Isaac ConnorandClaude Opus 4.8 5f702842a5 fix: stop the Config API leaking secret values refs GHSA-8g63-hqg8-82cv
Two ways a System=View account could read secrets through the Config API.

The oracle: ConfigsController::index() passed the caller's named filter to
buildFilter() and returned the matched rows. redactSecret() blanked a secret
Value in the response but not in the WHERE clause, so a filter such as
Name:ZM_AUTH_HASH_SECRET/Value LIKE:a% returned the row for a correct prefix
and nothing otherwise - the row count leaked the secret a character at a time,
and that secret signs auth tokens. index() now detects a filter on the Value
column and drops the secret rows from the result, so their presence reveals
nothing; a filter on any other column is unaffected.

The flags: ZM_JANUS_SECRET, ZM_UPLOAD_PASS and ZM_MQTT_PASSWORD held secrets
but were not marked Private, so the API returned them to System=View and
skin.js.php wrote them into every page as JavaScript constants. Mark them
private in ConfigData.pm.in (fresh installs) and add a Config UPDATE to the
untagged 1.39.41 migration (existing installs). No web page reads the three;
zmfilter, zmc and the Janus integration read them server side.

Tested: tests/php/test_config_value_filter.php (11 cases) covers the Value
detection, including Model.Value, case, and the DefaultValue non-match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-28 19:20:54 -04:00
Isaac ConnorandClaude Opus 5 2126ab799b feat: have tmpfiles.d age out the cache busting directory
cache_bust() in web/includes/functions.php symlinks every css and js file to a
name with the source file's mtime in it, so each time a source changes a new
link appears and the old one is left behind. Nothing has ever removed them.

The install this was written on had 8346 entries going back to April 2020,
1562 of them pointing at files that no longer exist -- one of which was the
log.js deleted in the log panel refactor, still being served because the skin
auto-includes views/js/<view>.js whenever that file is present. The directory
inode had grown to 823KB, which every lookup in that directory has to scan.

misc/zoneminder-tmpfiles.conf.in did not mention the directory at all, so
systemd neither created nor cleaned it. Add it as a d entry with a 30d age,
which the daily systemd-tmpfiles-clean.timer then acts on.

On the age, and why it is generous rather than a day or two: a symlink's mtime
and ctime are fixed when it is created, and neither being served nor having
its target read refreshes them -- verified here that traversing a symlink does
not update its atime either. So an age removes entries whether or not they are
in use, rather than only the unused ones. That is safe, because the directory
is derived and not authoritative: a link removed while still wanted is
recreated by the next page render, so the worst case is one missing asset on a
page that was already open. 30d keeps about a month of source versions for a
few recreated symlinks a month, where a short age would churn the whole set
repeatedly for no further benefit.

d and not D: D empties the directory at boot, which would throw away every
current entry on every reboot.

Tests: tests/php/test_tmpfiles_conf.php, 12 checks. Nothing exercises this
file during a build or a test run, and a mistake in it is quiet in both
directions -- a malformed line is skipped with a log message nobody reads, and
a missing age field just means a directory grows forever, which is how this
one got to 8346 entries. So the fields are parsed and checked, and the entry
is checked to name the same cmake variable that config.php.in defines
ZM_DIR_CACHE from, since if those two drift systemd would clean a directory
nothing writes to and nothing would report it.

The last check hands the file to systemd-tmpfiles itself, with every path
rewritten into a temporary directory first so that running a clean cannot
touch anything real. That check skips where systemd-tmpfiles is not installed.
Confirmed separately that a d entry with an age does remove symlinks, which is
what this directory is made of.

Verified the checks fail when the age is dropped, when d becomes D, when the
entry names a variable config.php.in does not use, and on an age systemd would
reject.

Ran: tests/php/test_tmpfiles_conf.php (12 passed), the rest of tests/php and
tests/js, npx eslint . (clean), utils/check-homoglyphs.py (clean).
test_bandwidth_clamp.php fails on this box for an unrelated reason: it cannot
read /etc/zm/conf.d/03custom.conf and the permission warning lands in its
captured output.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JpiSWBmtQkR5bcgpHWY4ME
2026-10-28 18:01:26 -05:00