Commit Graph
2801 Commits
Author SHA1 Message Date
Isaac Connor 55671fcd96 Merge pull request #5553 from AJ0070/5552-janus-pin-shm
perf: read the Janus pin from shared memory instead of running zmu
2026-11-12 19:52:58 -05:00
Jash 3f635686a1 fix: take a deleted event's DiskSpace off its Storage in the PHP delete refs #5605 2026-11-12 09:49:11 +05:30
Isaac Connor d34f26d14c Merge pull request #5538 from AJ0070/5537-daemon-check-once
perf: ask zmdc.pl whether ZoneMinder is running once a request
2026-11-11 21:49:14 -05:00
Jash bb36f9b5ac perf: read the Janus pin from shared memory instead of running zmu fixes #5552 2026-11-12 00:27:25 +05:30
Jash 3f1907960a perf: ask zmdc.pl whether ZoneMinder is running once a request fixes #5537 2026-11-11 19:49:28 +05:30
Jash 789d3c2254 fix: reject built-in preset names and match layout names literally when saving refs #3993 2026-11-11 09:31:05 +05:30
Jash a2941aa759 fix: overwrite your own montage layout when saving under its name instead of duplicating it, refs #3993 2026-11-08 14:45:43 +05:30
Isaac ConnorandClaude Opus 4.8 bf04cfe04c fix: refuse a path-traversal export name in exportEvents/downloadEvents refs GHSA-9hf5-jpww-rvpp
The export-generation path sanitized the user-supplied export directory name with
preg_replace('/[^\w\-.]/', '', ...), a whitelist that keeps dots, so a bare '..'
survived and $export_root became the parent of the export root. exportEvents()
then chmod'd, wrote into, and tarred that parent, and the archive was downloadable
through the safeExportComponent() read guard because it genuinely sat in the
exports dir. downloadEvents() had the same shape via DIR_EXPORTS_DOWNLOAD
(refs GHSA-72h2-rvhv-wr5g).

These are residual siblings of GHSA-fvx4-86xp-9v22, which hardened the download/
read views but left the write path. Refuse a '.'/'..' component in exportEvents(),
and route downloadEvents()'s name through the existing safeExportComponent().

Add tests/php/test_export_path_traversal.php.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-07 10:54:46 -05:00
Isaac ConnorandClaude Opus 5.5 ef29de86d4 fix: check SET_EVENT ids before authorising and packing them refs #4186
stream.php checked the target event's permission using the request
string and then packed intval() of it. On 32-bit PHP intval('2147483648')
is 2147483647, so the check and zms could see different events, and a
non-numeric or array value was cast to whatever intval() made of it.

The ids now have to be digit strings that fit in this PHP's int, or the
request is refused. The checked int is what gets packed. The packing
moved to includes/stream_set_event.php so tests/php can check the bytes
against EventStream::DecodeSetEvent's layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 19:32:53 -05:00
Isaac Connor 42706741d3 Merge remote-tracking branch 'upstream/master' into 5186-zms-ui-next-event 2026-11-04 18:41:28 -05:00
Isaac ConnorandClaude Opus 4.8 05a610a2c6 fix: revoke API tokens when a user's password is changed
Changing a user's password rewrote only the password hash and left the
user's JWT API tokens valid: a pre-change access token kept working and a
pre-change refresh token kept minting new access tokens for up to its 24
hour lifetime, so a leaked token survived the password change meant to
cut it off.

Set TokenMinExpiry to the change time in the same step that rewrites the
hash, so validateToken() rejects every token issued before the change,
matching the options page's existing revoke action. Covered paths: the
REST API User model (beforeSave), with the self-edit controller whitelist
widened to persist the field, and the classic web UI user action for both
the administrator edit and the self edit. The login-time upgrade of a
legacy hash to bcrypt rewrites the same password and is left untouched so
it does not revoke tokens.

refs GHSA-5w6w-qp25-2qqh

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-04 08:26:38 -05:00
Isaac ConnorandClaude Opus 5.5 9e3885e8fd refactor: remove ZM_OPT_FAST_DELETE
With fast deletes on, deleting an event in the web interface removed only
its Events row and left its Frames and Stats rows and its files for
zmaudit, and deleting a monitor left all of its events. zmaudit only runs
when ZM_RUN_AUDIT is on, and both options default to off independently,
so with fast deletes on and the audit off nothing ever removed them and
the Frames table grew without bound. In the Perl Event::delete the option
also kept zmfilter from removing the files of the events it purged.

Remove the option. ZM\Event::delete() always removes the Stats and Frames
rows and the files in one transaction with the Events row,
ZM\Monitor::destroy() always deletes the monitor's events, and the Perl
Event::delete deletes the files unless the storage area has DoDelete off.
zmupdate.pl rebuilds the Config table from ConfigData, so the option's row
goes away on upgrade without a migration. Drop the option from the docs,
from the zmaudit option help, and from the es_la, ro_ro and ru_ru
translations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 22:50:01 -05:00
Isaac Connor 9fef3b578a Merge pull request #5344 from IgorA100/patch-278747
Add a setting to enable/disable "backchannel" (a parameter used by Go2RTC) for the monitor.
2026-11-02 18:00:39 -05:00
Isaac Connor 4eda31b07d Merge pull request #5429 from jayhemnani9910/5416-audit-report-monitor-links
fix: give each event audit report row its own monitor link, fixes #5416
2026-11-02 08:41:10 -05:00
Isaac ConnorandClaude Opus 4.8 0fd646ef2e fix: reject path traversal in export download and archive views refs GHSA-fvx4-86xp-9v22
views/download.php and views/archive.php sanitized the user-controlled
`file` and `export_root` request parameters with str_replace('/', '')
only, which strips slashes but leaves `..` intact. export_root=.. made the
resolved path climb out of DIR_EXPORTS_DOWNLOAD into ZM_DIR_EXPORTS (and,
with file=.. as well, higher), and download.php then readfile()s it and,
from its shutdown handler, @unlink()s it. Any user with Events or Snapshots
view permission could read and delete files the web user can reach outside
the downloads directory.

Add safeExportComponent() and pathWithinExportDir() in
download_functions.php. The export file and directory names these views
handle are always single path components (zmExport_<connkey>.zip, a merged
'<Monitor> <start> to <end>.mp4'), so safeExportComponent() rejects any
value with a directory separator, a null byte, or a '.'/'..' traversal and
falls back to the generated default. pathWithinExportDir() resolves the
final path with realpath() and is checked in front of readfile() and
unlink(), so a path that still escapes the export directory - including
through a symlink - is refused.

Tests: tests/php/test_download_path_traversal.php

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-01 22:04:58 -05:00
Isaac Connor 3a41f9d634 Merge pull request #5423 from connortechnology/5418-current-weekday
fix: make Current Weekday filter terms run in the web UI and zmfilter.pl
2026-11-01 21:57:56 -05:00
Jay Hemnani 6cae4738e2 fix: give each event audit report row its own monitor link, fixes #5416 2026-11-02 04:08:13 +05:30
Isaac ConnorandClaude Opus 5.5 960d8feef7 fix: make Current Weekday filter terms run in the web UI and zmfilter.pl refs #5418
FilterTerm::sql_attr() returned 'weekday(NOW()' without its closing
parenthesis, so any filter with a Current Weekday term failed with
"Database query failed". FilterTerm::valid() treated the value 0 (Monday) as
missing, so a Monday term was dropped and the filter matched every event.

ZoneMinder::Filter had no CurrentWeekday case at all and emitted
E.CurrentWeekday, a column Events does not have, so zmfilter.pl could not run
such a filter either. Emit weekday(NOW()) there as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 17:29:02 -05:00
Nic BoetandClaude Opus 5.5 481db3422a docs: say why corsAllowedOrigin() lives in Network.php
Network.php's header said policy decisions involving addresses do not
belong there. corsAllowedOrigin() is one, kept there because the web UI
and the API share it and functions.php cannot be loaded by a standalone
test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 17:21:45 -05:00
Nic BoetandClaude Opus 5.5 96804bca31 fix: allow CORS only for exact server and same-host origins
CORSHeaders() (web UI) and AppController::beforeFilter() (API) send
Access-Control-Allow-Origin with Access-Control-Allow-Credentials: true.
With no Servers rows and ZM_MIN_STREAMING_PORT set they reflected any
Origin, and with Servers rows they matched the Origin against each
server's Hostname and Name with a regex anchored only at the start, so
https://zm.example.com.evil.net was accepted for zm.example.com.

Both now call corsAllowedOrigin() in Network.php, which accepts an
Origin of the form scheme://host[:port] whose host equals a server's
Hostname or Name, or, without Servers rows and with streaming ports,
the host this request was made to. Any port is accepted, so multi-port
streaming keeps working. Same-origin and unlisted origins get no CORS
headers, as before; the web UI still warns about unlisted origins only
when Servers rows exist.

Tests: tests/php/test_cors_allowed_origin.php

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 17:21:45 -05:00
IgorA100 06b58aa2ae Merge branch 'master' into patch-278747 2026-11-01 22:17:26 +03: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 82ce0be4bd fix: restrict <base> to the same origin in the web CSP
The policy allows any script that carries the page nonce, wherever it is
loaded from, and the skin's nonced scripts use relative srcs. Markup
injected into a page before them (an unescaped request value) could add
<base href> pointing at another host, and the browser then loaded and
ran that host's script with the nonce.

Add base-uri 'self'. ZoneMinder doesn't use <base>; jQuery's parseHTML
sets one to the page's own URL in a detached document, which 'self'
still allows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 23:01:19 -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 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
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 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
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 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 2985fb9154 fix: new session id when an auth= or stateful API login takes a session
An auth= login (ZM_AUTH_HASH_LOGINS) and the API's stateful login
(stateful=1 with user/pass, legacy API auth) wrote the user into the
session the client arrived with, keeping its id. With an id planted in
the client beforehand, the attacker's cookie became the victim's
session. The login form already issues a new id.

Both now call zm_session_regenerate_id_login() first: auth= when a
session the client carries a cookie for changes to another user, the
API whenever credentials log in. The API's cookie path no longer logs
the whole session.

The API's stateful login also drops $_SESSION['password'] =
$_REQUEST['password']. This is not a behaviour change: API logins send
pass=, not password=, so under ZM_AUTH_RELAY=plain the line stored
nothing for them. A stateful request that logs in with username= and
password= goes through zm_authenticate_request()'s form-login path,
which stores the password itself, as before. zmu gets its credentials
from zmuCredentials() (the zmu token change, which this one follows).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit bb3bd92b92)
2026-10-31 09:04:37 -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
Nic Boet 01ac955ad9 refactor: move zmuCredentials() above zm_authenticate_request()'s comment
zmuCredentials() was inserted between zm_authenticate_request() and the
comment that documents it. Move the function and its own comment above
that block. No code change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 0779162df844ea6bfd45fd3b88c0e30ad922b7ef)
2026-10-30 19:30:28 -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 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
IgorA100 ee47d85d1a Merge branch 'master' into patch-278747 2026-10-29 18:57:41 +03:00
Isaac ConnorandClaude Opus 5 696b479a88 fix: qualify the remaining logger calls in the web ui, and test for them
Looking for other instances of the CronTab.php fatal in the previous commit
found eleven, in ten files, dating from 2019 to 2023. Each is a call to a
logger function from the global namespace without the \ZM\ prefix, so each is
a fatal the moment its branch runs:

  web/ajax/console.php, events.php, reports.php, add_monitors.php, status.php
  web/includes/actions/snapshot.php (two), donate.php
  web/includes/functions.php, session.php
  web/views/image.php

They have survived this long because of where they sit. Every one is on an
error or diagnostic path -- an invalid sort order, a zero byte download, a
failed read lock -- so the call is only reached when something has already
gone wrong, and then it turns a handled problem into a blank 500. That is the
shape of the bug on the monitor save: the write had worked, and the thing that
broke was the attempt to log.

Verified before changing any of them that each file is in the global
namespace, does not define the function itself and does not import it, so the
call really does not resolve.

Tests: tests/php/test_logger_calls_qualified.php, 16 checks. It tokenizes
every php file under web/ and reports unqualified calls, with the function
names read out of logger.php rather than listed, so a new one is covered the
day it is added. web/api is skipped as cakephp with its own logging, and
assets as third party.

Php's own tokenizer rather than a regex, because the distinctions matter: a
method call on an object that happens to have an Error() method is fine, as
is a definition, a mention, a qualified call, the same call from inside
namespace ZM, and the name appearing in a comment or a string. There is a
check for each of those, since a scan that quietly matched nothing would pass
the tree-wide check on its own.

Verified the scan fails when the Debug() in CronTab.php is put back.

Ran: tests/php/test_logger_calls_qualified.php (16 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
Isaac ConnorandClaude Opus 5 afa5b14307 fix: qualify the logger calls in CronTab.php refs #4957
Saving a time based action on a monitor died with

  PHP Fatal error: Uncaught Error: Call to undefined function Debug() in
  includes/CronTab.php:280

and the browser showed only "An error occurred while saving data", because
the save goes over ajax and a fatal gives it a 500 with nothing to report.
The action itself had already been written to the database; what failed was
the crontab rebuild that follows it.

Debug(), Info(), Warning() and Error() are defined in includes/logger.php,
which is namespace ZM. CronTab.php is in the global namespace, so they have to
be called as \ZM\Debug(...) -- php resolves a function name against the
current namespace and then the global one, and these are in neither from
there. Four calls were bare: the Debug at the end of cronRebuild and three
Error/Warning calls on failure paths.

Nothing catches this at include time, php -l is happy with it, and the file
works until the one branch holding the call is taken. The Error calls here are
on paths that only run when crontab itself fails, so they could have sat
unnoticed for much longer than the Debug did.

A follow-up commit adds a test that scans for this, and fixes the ten other
places in the tree that have the same bug.

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
Isaac ConnorandClaude Opus 5 78f389cdea feat: add ZM_ALLOWED_COMMANDS to restrict what filters and tasks may run refs #4957
Two places in ZoneMinder run a command the operator typed: a filter with
"Execute command", and the scheduled tasks added for #4957. Both run it as the
web user through a shell, which is close to shell access on the server. Until
now the only control over that was who may edit, and the answer was anyone
with System rights.

ZM_ALLOWED_COMMANDS names the programs that may be run, comma separated.
Empty is the default and places no restriction, so an upgrade changes nothing
and the filters people already have keep working; setting it narrows both
features at once.

Only the program is matched, because an exact whole-command match could never
work for filters: zmfilter.pl appends the event path to whatever the filter
stored, so no two runs have the same command line. Arguments are therefore
free, which means the program being on the list has to be the whole of the
guarantee -- so while a list is in force a command may not contain the
characters that start another program: semicolon, pipe, ampersand, backtick
and dollar-paren. Without that, "/usr/local/bin/backup.sh; anything" would
pass on the strength of its first word. Redirection is deliberately allowed;
it starts no program, and refusing it would break the ordinary
"... >> /var/log/mine.log".

Refused in three places, because each answers a different question. The
filter and scheduled task editors refuse on save, so the operator is told at
the time rather than by a log line days later. zmfilter.pl refuses at the
moment it runs, because a row can reach the database without passing through
the web ui and because the setting may have been narrowed since. And
cronRebuild leaves a newly disallowed task out of the crontab, so tightening
the setting takes jobs away rather than waiting for somebody to edit each one.

The rule exists twice, in web/includes/Command.php and ZoneMinder::General,
since one is PHP and the other Perl. Rather than hope they stay in step,
tests/php/test_allowed_commands.php puts every case to both and fails if they
disagree. That earned itself immediately: both split the command on
whitespace before handling quotes, so a program path containing a space was
cut in half and compared as the wrong string. The cross-check found it in
both at once.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-28 18:01:25 -05:00