Skip to content

Stream abuse: enforce stream caps across replicas, and a kill switch for over-cap and terminated sessions #305

Open

Description

@CoffeeKnyte

Problem

Silo has no way to stop a stream once it has started. Concurrency limits (users.max_streams) are checked only at admission, in the local API process, and only for streams that ask permission through the normal front door. That leaves three classes of misbehavior we cannot currently answer:

  • Bad actors / re-streamers (e.g. Stremio-style). A client can hold a valid 24h stream token and pull bytes indefinitely. If it never reports playback progress — or reports false progress — the server today has no independent, authoritative record that the stream even exists, let alone a way to stop it. "Please stop" is a request the client is free to ignore.
  • Concurrency-cap violations across nodes. The admission check lives in one process's memory. In a multi-node deployment (edge proxy/transcode nodes) or with several central replicas, a single user can open more concurrent streams than their max_streams allows, because no one is counting the live picture across the whole fleet.
  • Admin termination doesn't stick. When an operator terminates a session, we send a cooperative realtime "stop" command. A cooperative client stops; an abusive or badly-coded one keeps pulling segments. There is no server-side enforcement that makes a terminate actually terminate.

An operator watching their deployment cannot reliably answer "who is streaming what right now" (integrated single-node deployments were effectively blind to their own sessions), and cannot make a stream stop against a client's will.

Goal

Gain control over stream abuse — concurrency-cap violations, admin termination, and re-streaming abuse — without putting the central database on the per-segment hot path and without changing the client-facing token protocol.

The strategy is deliberately two-part, in order:

  1. First-class monitoring first — know about every stream, none hidden, and never trust the client. The server is the one serving the bytes, so it inherently knows a stream is alive. Existence is server-observed on every playback path (integrated + multi-node, native + jellycompat, direct/remux/transcode); it is never gated by a client progress report, so a disguised re-streamer that withholds or falsifies progress is still counted. Monitoring reports to central asynchronously — central (or an edge node) serves the session first, then tells the monitor — so it stays off the hot path. We accept that a stream can run for a few seconds before it shows up; that is fine for a media server.

  2. Then a kill switch — stop anything that should be stopped, and keep it dead. Once monitoring is authoritative, enforcement collapses to one action: write a revocation to a small kill list. The kill list lives in memory (integrated) or Redis (multi-node) so that neither integrated nor multi-node deployments have to consult the database on the hot path — the only per-segment addition is an in-memory set-membership check. On a hit the serve surface refuses the request and cuts any in-flight connection. Kills propagate to edges via pub/sub (+ a poll safety net) and take effect within ~120s, which is acceptable.

An async decision engine (the "brain") sits fully off the hot path: it reads the live monitoring picture, compares each user's live count to max_streams, and revokes over-cap victims. Admin terminate and account-session revocation write into the same kill list. Every reason — over-cap, admin terminate, re-streaming heuristic — collapses to the same primitive.

Acceptance criteria

  • Authoritative monitoring: a stream that plays while sending no client progress reports still appears in the live picture and still counts against the cap; it ages out on its own once it stops pulling bytes. Coverage is complete across server layout × playback type × route.
  • Enforcement off the hot path: the only per-segment cost is an in-memory lookup; no per-segment Redis or Postgres. Existing playback is unaffected when nothing is revoked.
  • Kills stick and stay dead: a revoked session stops within ~one poll interval and a reconnect with the same still-valid token is refused. A kill survives a server restart or a Redis flush (otherwise restart-resilient playback would reconstruct and re-serve an already-killed stream).
  • Over-cap enforcement: start N+1 concurrent streams for a capped user → the over-cap stream(s) are killed within ~120s and stay dead; under-cap users are untouched; the enforcer fails open on lookup errors (never kills on uncertainty).
  • Admin terminate is enforced, not merely requested; account-session revocation also kills the user's live streams.

Non-goals / out of scope

  • Turning the 24h stream token into a short-lived play ticket (rejected: Silo's master.m3u8 is a VOD playlist fetched once, so short tickets would expire mid-movie; and flipping the global token TTL is a break-all-playback change that can't be behaviorally verified without real clients).
  • Replacing the DB-backed opslog admin log viewer (see the observability epic Epic: clean, persistent monitoring & observability #265).
  • Enabling the re-streaming abuse heuristic by default — it ships disabled until tuned against real traffic to avoid false kills.

Related

Activity

  1. bakes82 commented on Jul 5, 2026

    @bakes82

    Concurrency limits for things like Stremio do not always make sense because, depending on the client, someone could have a very large cache and download the entire file in seconds or minutes, depending on their internet speed and peering to the server.

    I do agree with using short-lived tokens, though. If the goal is to manage or sell Stremio streams, concurrency does not seem like the best way to control usage. Since there is no transcoding involved, traffic-based limits would likely make more sense.

    For reference, there are large providers that sell appboxes and also offer Stremio access. From what I have seen, they use short-lived tokens, usually around five minutes give or take. As long as the stream remains active and continues pulling data, it works fine. But if someone tries to reuse the same link after that five-minute window, the key is no longer valid.

  2. added
    bug
    triaged
    and removed
    triaged
    on Sep 20, 2026
  3. added theissue type on Sep 20, 2026
  4. removed
    bug
    on Sep 20, 2026
  5. Rhainland commented on Oct 11, 2026

    @Rhainland
    Contributor

    Reproduced the cross-replica part of this on current main (a6a620cb1) during the #1216 validation, with two API replicas sharing one Postgres and Redis and no remote nodes:

    1. Set an account's Max streams to 1.
    2. POST /api/v2/playback/start for that account on replica A: playable.
    3. A second start on replica A: refused with capacity_unavailable, as expected.
    4. The same second start on replica B: playable.

    GET /api/v2/admin/sessions on either replica then lists two live sessions for the account. Admission counts only the sessions in the receiving process's SessionManager (activeCountLocked / transcodeCountLocked in internal/playback/session.go), so each replica grants the account its full allowance. Max transcodes works the same way.

    #1216 records this as a known limitation for 1.0 and points here instead of opening a separate issue.

  6. changed the title [-]Protect against stream abuse: authoritative monitoring + kill switch for cap violations, admin terminate, and re-streaming[/-] [+]Stream abuse: enforce stream caps across replicas, and a kill switch for over-cap and terminated sessions[/+] on Oct 28, 2026
  7. CoffeeKnyte commented on Oct 28, 2026

    @CoffeeKnyte
    ContributorAuthor

    Narrowing this to what is left. #306 was closed unmerged, and #667 landed the monitoring half on its own.

    Done on main (564b906):

    • Server-observed monitoring: internal/streamtelemetry measures bytes on every serving path and merges records across publishers, so a stream shows up whether or not the client reports progress.
    • Stopping an unreachable player: after fix(playback): end a player an administrator stopped while it was unreachable #2280, an admin stop ends the playback attempt, and later progress or replan calls get 410 playback_session_ended.

    Still missing:

    • Caps across replicas. Admission counts only the receiving process's sessions (activeCountLocked and transcodeCountLocked, internal/playback/session.go:1861 and :1885), so each API replica grants the full max_streams and max_transcodes. This is the gap reproduced above and recorded in [v1] Server limits & audit logs #1216.
    • A kill list. Nothing refuses a revoked session's still-valid stream token on segment requests, or keeps it refused after a restart.
    • An over-cap enforcer. Nothing ends streams that go over the cap after admission.
    • Account sign-out. Revoking an account's login sessions does not end its live streams.

    Re-stream detection was closed as a rare edge case in #522. #2283 (admin commands landing on another replica) is related but separate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions