Skip to content
This repository was archived by the owner on Nov 18, 2026. It is now read-only.

feat(streaming): RTSP video sources through the video gateway - #381

Closed
edospadoni wants to merge 13 commits into
ns8from
feat/rtsp-video-sources
Closed

edospadoni wants to merge 13 commits into
ns8from
feat/rtsp-video-sources

Conversation

@edospadoni

@edospadoni edospadoni commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Server side of NethServer/dev#7535: RTSP video sources (door intercoms, cameras) played by the CTI clients over WebRTC through the MediaMTX video gateway of the module, with door opening by DTMF or HTTP(S) action URL.

Related PRs:

Changes

  • Sources API (GET /streaming/sources): same keys as before, but url, user and password are always empty, so device addresses and credentials never reach the clients (call events included). New keys: type (image/rtsp), whep (stream URL for RTSP sources) and gates (id, name, type only).
  • Stream token (POST /streaming/token): 60 s single-use token bound to user and source, checked against the vs_* permission. Clients send it only in the Authorization: Bearer header of the WHEP request.
  • Gateway authorization hook (POST /mediamtx/auth on the streaming REST port): allows only WebRTC readers with a valid token for that source; unknown paths are denied. It answers only loopback requests not forwarded by a proxy and it is outside the prefixes routed by the HTTP proxy.
  • Revocation: sessions are kicked through the gateway control API when the user loses the permission or the source is removed (checked right after a configuration or authorization reload and every 30 s); sessions unknown to the server (e.g. after a restart) are kicked after a grace time.
  • Gates (POST /streaming/open with optional gate): several gates per source, opened by DTMF (only on an answered call, otherwise 409 call_not_answered) or by an HTTP(S) action URL called by the server with the gate credentials (Basic or Digest, 5 s timeout). Without gate the first one is opened, as released clients expect. The gate identifier is the global id of a gate returned by streaming/sources, not its position in the source (the REST doc examples say so). A failed DTMF sequence answers 502 dtmf_failed, also for the legacy open code of sources without gates (it answered a generic 500).
  • Image sources support credentials (Basic and Digest) and the "skip TLS verification" option. RTSP sources are never sampled. streaming/image answers 502 source_certificate_changed (instead of 500) when the device presents another certificate than the pinned one. The sampler logs an error again when it changes (for example a device restart followed by a certificate change), not only the first one until a success.

Security hardening

Done after a code review and a live penetration test on a test instance:

  • The gateway control API is allowed only to the internal user nethcti-server with the per-instance password from services.json, compared in constant time.
  • Single-use tokens (bound to the first gateway session they open) and limits: 3 sessions per user and source, 30 per user, 300 tokens per user per minute (429 too_many_sessions / too_many_requests); denials are logged.
  • With "skip TLS verification", https:// snapshot URLs and URL gates must match the certificate fingerprint pinned by FreePBX, checked before any request or credential is sent. Sources saved without a fingerprint keep working unpinned and are logged.
  • Device addresses are resolved and loopback, link-local and unspecified destinations are refused (any numeric form, IPv4-mapped IPv6 included); LAN addresses are allowed.
  • Requests to devices follow no redirects; snapshot bodies are capped at 5 MB, gate responses at 64 KB.
  • DTMF codes are no longer sent to clients. For sources with gates cmdOpen is the placeholder *, so the open door button of released clients (phone-island 1.1.8 and older) keeps working: they call streaming/open without a gate.
  • streaming/open accepts only a string or numeric gate identifier.
  • DOM XSS fixed in the legacy notification popups (static/templates/notification_popup/call.html and streaming.html): query string values are written as text and URLs/identifiers are validated.

Testing

  • Plain node tests in plugins/streaming/test and plugins/com_streaming_rest/test: parsing, payload sanitization, tokens and limits, hook decisions, gateway API user, revocation, gates, pinning and address checks, snapshots.
  • Validated manually on a test NethVoice instance with the module and clients of the sibling PRs: video in the CTI Streaming page and in the call preview of web CTI and NethLink, DTMF and URL gates, permission revocation, source deletion, camera down/up, RTSPS with a self-signed certificate.
  • Live retest of the security fixes on the same instance: 14 of 16 checks passed; the regression found (ffmpeg build in the module) is fixed in ns8-nethvoice#1184, the remaining known issue is outside these PRs.
  • Tested with a real Fanvil i62 door phone: video in the Video sources page, video and door opening by DTMF during a call, incoming call.
  • Not done yet: RTSPS with a real device, positive-case test of the https pinning.

Notes for reviewers

  • streaming.json written by older FreePBX versions (no type, no gates) keeps the previous behaviour.
  • No new dependencies; code targets the Node.js 14 runtime of the module image.
  • Out of scope, to be tracked separately: the internal plugin ports trust the authorization_user header from local processes (pre-existing design).

Before merge

ns8-nethvoice#1184 pins this branch by commit (NETHCTI_SERVER_COMMIT): after merging, that pin moves to the merged ns8 commit. Merge order: this PR → phone-island#315 (release) → nethvoice-cti#630 (release) and nethlink#263 → ns8-nethvoice#1184.

Refs NethServer/dev#7535

- sources API no longer returns device addresses and credentials, adds
  type, WHEP url and gates
- short-lived stream tokens and the authentication hook of the video
  gateway (MediaMTX), with revocation of the sessions when a permission
  or a source is removed
- several gates per source, opened by DTMF or by an HTTP action URL
  called by the server (Basic/Digest)
- image sources with credentials
The tls_skip_verify flag of a source applies to its snapshot requests
and to its URL gates only.
PlayDTMF on a ringing channel reports success but the tones are lost:
return 409 call_not_answered instead of a false success.
- with "Skip TLS certificate verification" the certificate of an https://
  snapshot URL or URL gate must match the SHA-256 fingerprint pinned by
  FreePBX when the source was saved: the connection is opened and checked
  before the request (and the credentials) is written. Sources saved by an
  older version (no fingerprint) keep working unpinned and are logged.
- the device address is resolved and loopback, link-local and unspecified
  addresses are refused (any numeric form, IPv4-mapped IPv6 included),
  LAN addresses are allowed
- redirects are never followed, snapshot bodies are limited to 5 MB and
  gate responses to 64 KB
- gate errors gate_certificate_changed and gate_address_not_allowed
The clients read cmdOpen only for the configurations without gates: for
the other sources it is empty, the gates are opened by the server.
…ions

- the control API of the gateway is no longer excluded from the hook: it is
  allowed only to the internal user nethcti-server with the password of
  services.json (mediamtx.api_password), compared in constant time, sent
  by this server as HTTP Basic; without a password the API is not used
- a stream token opens a single gateway session (bound to the first
  session id the gateway authorizes); at most 3 sessions per user and
  source and 30 per user, refreshed from the gateway before denying, and
  at most 300 tokens per user per minute: 429 too_many_sessions or
  too_many_requests from streaming/token, denials logged
- the token is read only from the Authorization header, never from the
  query string
Arrays and objects are refused with 400 invalid_gate (numbers are still
accepted). The documented errors of streaming/open include 409
call_not_answered and the new gate errors.
The call and streaming popups wrote the caller name, number and source
description from the query string as HTML on the CTI origin. They are
written as text now; the image URL must be a same-origin path or an
http(s) URL, the source id a plain identifier, the server image a data
URL of an image and the CTI protocol http or https.
…e checks

The fake devices listen on a non-loopback address: loopback devices are
refused now.
The clients released before the gates (phone-island 1.1.7 and older, in
NethLink and the CTI) show the open door button only when cmdOpen is not
empty, and the button calls streaming/open without a gate: the server
opens the first gate. A source with gates now sends "*" instead of an
empty cmdOpen, never its DTMF code; the newer clients ignore cmdOpen when
gates is present, and a source without gates still sends an empty one.
The sampler logged only the first error of a source until a success, so
after a device restart (ECONNREFUSED) a later TLS_FINGERPRINT_MISMATCH was
never logged. The last error code of each source is kept: an error is
logged again only when it differs from the previous one.
streaming/image answered a plain 500 when the device of an image source
presented another certificate than the pinned one. It answers 502 with
{ code: "source_certificate_changed", message } now, like the
gate_certificate_changed error of streaming/open; the other failures are
unchanged.
The sources without gates use their "open" code: a failed DTMF sequence
now returns the same "dtmf_failed" error of the DTMF gates instead of a
generic 500. The REST doc of streaming/open says that the gate identifier
is the global "id" of a gate returned by streaming/sources.
@edospadoni
edospadoni force-pushed the feat/rtsp-video-sources branch from c45bba0 to fadbc15 Compare November 17, 2026 09:06
@edospadoni

Copy link
Copy Markdown
Member Author

Superseded by nethesis/ns8-nethvoice#1184. After the monorepo import (nethesis/ns8-nethvoice#906) these changes live in the nethcti-server folder of the module, with the same commits. Refs NethServer/dev#7535

@edospadoni edospadoni closed this Nov 18, 2026
@edospadoni
edospadoni deleted the feat/rtsp-video-sources branch November 18, 2026 16:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant