Skip to content

ABS compat: download privilege (download_allowed) not enforced — restricted users can download audiobooks #141

Closed

Description

@slimshizn

Summary

The ABS-compatible API ignores Silo's per-user download privilege
(users.download_allowed / models.User.DownloadAllowed). Users with downloads
disabled can both see download UI in Audiobookshelf clients and successfully
download complete audiobook files through the compat listener.

The native download path enforces this correctly
(internal/download/service.go returns ErrDownloadNotAllowed); the ABS layer
simply never wired the check in.

Steps to reproduce

  1. Create a non-admin user and disable downloads (download_allowed = false).
  2. Connect to the ABS listener (:13378) with the official Audiobookshelf app
    and log in as that user.
  3. Download succeeds. Equivalently, a direct authenticated request works:
    GET /api/items/{libraryItemId}/file/{ino}/download.

Expected: download UI hidden and the request rejected with 403.
Actual: file is served.

Root cause (two independent gaps)

  1. No server-side enforcement. handleFileStream
    (internal/audiobooks/abs/file_handler.go) backs both
    GET /api/items/{libraryItemId}/file/{ino} and the /download variant.
    It checks authentication (absAuthFrom) and library access
    (accessFilterForAuth), then serves the file — DownloadAllowed is never
    consulted.

  2. Login payload advertises the permission. The ABS login response
    (internal/audiobooks/abs/login.go, permissions block) hardcodes
    "download": true for every user, so client apps render download UI
    unconditionally. (update / delete / upload / accessExplicitContent
    are also hardcoded true — lower stakes today since the compat layer
    doesn't implement those mutations, but same pattern.)

Why the fix is safe for playback

ABS playback does not stream through the file route: handlePlayStart
issues short-lived session-scoped track URLs
(/abs/public/session/{sid}/track/{idx}, see play_response.go). The
/file/{ino} routes are purely the offline-download/save surface, so both
variants can be hard-gated on DownloadAllowed without affecting streaming
for restricted users.

Suggested fix

  • In handleFileStream: load the authenticated user and return 403 when
    !user.DownloadAllowed, for both the bare and /download variants.
  • In the login response (and /api/me if it echoes a permissions object):
    report the real value, "download": user.DownloadAllowed, so compliant
    clients hide the download UI.
  • Consider deriving the other hardcoded permission flags from real state while
    in there, or leaving a comment explaining why they remain true.

Notes

  • Native download service (internal/download/service.go) is the reference
    behavior: checkEnabled + if !user.DownloadAllowed → ErrDownloadNotAllowed.
  • Worth a follow-up sweep: RSS feed file routes (/feed/{slug}/file/{ino}) are
    public by design (podcast semantics) — confirm feed creation is the
    intended gate for restricted users.

Activity

  1. added
    v1.0
    on Jun 12, 2026
  2. added this to the v1 milestone on Jun 12, 2026
  3. added
    v1.0-proposed
    v1.0
    and removed
    v1.0
    v1.0-proposed
    on Jun 13, 2026
  4. Tobechukwu-Njoku commented on Aug 24, 2026

    @Tobechukwu-Njoku
    Contributor

    Still reproducible on main at 820eef77 — and there's some history here worth surfacing before anyone writes this again.

    The gap is unchanged

    internal/audiobooks/abs/ contains no reference to DownloadAllowed / download_allowed at all. The three surfaces that serve raw bytes or advertise the capability are all unguarded:

    • file_handler.go — handleFileStream (:55) checks auth (:57) and library access via accessFilterForAuth, but nothing consults the download privilege.
    • rss_feeds_handler.go — same.
    • login.go:267 — still emits "download": true unconditionally, so ABS clients render the offline-save UI regardless of the account's privilege.

    The native path meanwhile enforces at internal/downloads/policy.go:176 and :204, through policyengine.ActionDownload.

    There was already a fix, and it was withdrawn

    #234 ("fix(audiobooks): enforce download privilege on ABS-compat download routes") covered exactly these three surfaces via a narrow abs.DownloadPolicy dependency. @Quick104 opened it 2026-06-26 and closed it 2026-07-01 without comment.

    The dates are suggestive: #282 ("access groups + embedded OPA policy engine with decision audit log", 42602b78) merged 2026-07-05, four days later. That refactor introduced internal/policy, whose input.go:4-5 reads:

    // ActionDownload checks whether a user may create or serve original downloads.
    ActionDownload = "download"

    "or serve" describes this case exactly. So my read is that #234 wasn't wrong so much as overtaken — a bespoke adapter threaded through the ABS handler stopped being the right shape once a general policy engine existed. That is inference on my part, not something I can see stated anywhere, so please correct it if the reason was different.

    Either way the ABS layer never got wired into the new engine, so the hole outlived the refactor.

    What I'd like to know before doing anything

    Which enforcement point do you want?

    1. Through the policy engine — have the ABS surfaces call policyengine.ActionDownload the way internal/downloads does, so one policy governs both stacks and the decision lands in the audit log. handleFileStream already has a.UserID in hand, so the identity is available.
    2. Revive fix(audiobooks): enforce download privilege on ABS-compat download routes #234's shape — the standalone abs.DownloadPolicy dependency, if there's a reason the compat layer should stay decoupled from the policy engine.
    3. Something else that fits a plan I can't see from outside.

    Happy to implement whichever you prefer, including the login.go capability flag so clients stop advertising downloads to accounts that can't use them. I held off writing it because this is an authorization behavior change and CONTRIBUTING asks to coordinate those first — and because the last attempt was withdrawn for reasons I'd rather understand than re-derive.

  5. removed this from the v1 milestone on Sep 19, 2026
  6. added
    bug
    triaged
    and removed
    triaged
    on Sep 20, 2026
  7. added theissue type on Sep 20, 2026
  8. removed
    bug
    on Sep 20, 2026
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

    v1.0-proposed

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions