Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix authentication bypass in stream proxy - #471

Draft
xbmc4lyfe wants to merge 1 commit into
mainfrom
sentinel-fix-auth-bypass-9880259692204535171
Draft

πŸ›‘οΈ Sentinel: [CRITICAL] Fix authentication bypass in stream proxy#471
xbmc4lyfe wants to merge 1 commit into
mainfrom
sentinel-fix-auth-bypass-9880259692204535171

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: Stream proxy dispatch token check bypasses authentication when expected_token is missing or empty.
🎯 Impact: Unauthenticated attackers can access critical endpoints like /prepare and /fallbacks.
πŸ”§ Fix: Ensure _prepare_token_ok explicitly fails closed when expected_token is falsy and correctly checks supplied_token.
βœ… Verification: Covered by existing tests.


PR created automatically by Jules for task 9880259692204535171 started by @xbmc4lyfe

Co-authored-by: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

βœ… No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions github-actions Bot added the addon label Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

πŸ“ Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an authentication issue affecting stream preparation and fallback requests when a required security token was unavailable.
    • Requests now fail safely instead of being accepted without valid credentials.
    • Improved handling of missing or invalid token values during verification.
  • Documentation

    • Added a security incident record and prevention guidance describing the authentication fix.

Walkthrough

The stream proxy dispatch layer adds prepare and fallback POST handling, bounded request validation, stream response cleanup, and HEAD/GET routing for regular and HLS media. Prepare-token checks now fail closed when the expected secret is absent.

Changes

Stream proxy dispatch

Layer / File(s) Summary
Request validation and authentication
repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py.orig, repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py, .jules/sentinel.md
The dispatch mixin validates JSON framing and prepare parameters, routes POST requests, and rejects missing prepare tokens before comparison.
Preparation and fallback updates
repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py.orig
Preparation responses include stream metadata, failures map to HTTP responses, and late fallback sources are merged into active sessions.
Media and HLS routing
repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py.orig
HEAD and GET requests route regular and HLS resources, validate segment formats, and release acquired stream contexts.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant _DispatchMixin
  participant proxy
  participant StreamContext
  Client->>_DispatchMixin: POST /prepare
  _DispatchMixin->>_DispatchMixin: Validate token and request body
  _DispatchMixin->>proxy: Call prepare_stream
  proxy-->>_DispatchMixin: Return stream metadata
  Client->>_DispatchMixin: GET media or HLS resource
  _DispatchMixin->>StreamContext: Acquire and validate context
  StreamContext-->>Client: Return media response
  _DispatchMixin->>StreamContext: Release context
Loading

Poem

A rabbit checks the token tight,
No secret means β€œdeny” tonight.
Streams hop through routes with care,
Fallbacks join the session hare.
HLS segments dance in rowsβ€”
Safe little burrows, where data flows.

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly identifies the main fix: an authentication bypass in the stream proxy.
Description check βœ… Passed The description matches the change and accurately states the fail-closed token check fix.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel-fix-auth-bypass-9880259692204535171
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch sentinel-fix-auth-bypass-9880259692204535171

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Python

Python / code-coverage/pytest

The overall coverage in commit 0df3505 in the sentinel-fix-auth-by... branch remains at 88%, unchanged from commit 000221a in the main branch.

@codacy-production

Copy link
Copy Markdown
Contributor

Up to standards βœ…

🟒 Issues 0 issues

Results:
0 new issues

View in Codacy

🟒 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py (1)

29-33: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | πŸ’€ Low value

Align the docstring with the fail-closed behavior.

Lines 29-33 reject missing tokens rather than coercing both values to ""; update Lines 25-26 so the documented behavior matches the implementation.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py`
around lines 29 - 33, Update the docstring for the token validation method
surrounding the expected_token and supplied_token checks to document fail-closed
behavior: missing expected or supplied tokens are rejected, not coerced to empty
strings. Keep the existing validation logic unchanged.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py.orig`:
- Around line 356-359: Ensure the stream context acquired by
_get_stream_context(acquire=True) is released before returning from the
invalid-context branch when ctx is None or its mode is not "hls". Preserve the
existing 404 response, and keep valid HLS requests flowing through the normal
release path.

---

Nitpick comments:
In `@repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py`:
- Around line 29-33: Update the docstring for the token validation method
surrounding the expected_token and supplied_token checks to document fail-closed
behavior: missing expected or supplied tokens are rejected, not coerced to empty
strings. Keep the existing validation logic unchanged.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e8457c2-c020-4cde-866e-d059d150b7cd

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 000221a and 0df3505.

πŸ“’ Files selected for processing (3)
  • .jules/sentinel.md
  • repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py
  • repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py.orig
πŸ“œ Review details
⏰ Context from checks skipped due to timeout. (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: coverage
  • GitHub Check: test
  • GitHub Check: Analyze (python)
  • GitHub Check: lint
  • GitHub Check: Analyze (python)
πŸ”‡ Additional comments (1)
.jules/sentinel.md (1)

7-11: LGTM!

Comment on lines +356 to +359
ctx = self._get_stream_context(acquire=True)
if ctx is None or ctx.get("mode") != "hls":
self.send_error(404)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚑ Quick win

Release contexts rejected for non-HLS mode.

Line 356 acquires the context, but the non-HLS return at Line 359 skips the finally release. A request to an HLS path for a live non-HLS session can leave that context acquired and pin the session.

Proposed fix
         ctx = self._get_stream_context(acquire=True)
-        if ctx is None or ctx.get("mode") != "hls":
+        if ctx is None:
             self.send_error(404)
             return
         try:
+            if ctx.get("mode") != "hls":
+                self.send_error(404)
+                return
             _session_id, resource = parsed
             seg_fmt = ctx.get("hls_segment_format", "mpegts")
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ctx = self._get_stream_context(acquire=True)
if ctx is None or ctx.get("mode") != "hls":
self.send_error(404)
return
ctx = self._get_stream_context(acquire=True)
if ctx is None:
self.send_error(404)
return
try:
if ctx.get("mode") != "hls":
self.send_error(404)
return
_session_id, resource = parsed
seg_fmt = ctx.get("hls_segment_format", "mpegts")
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@repo/plugin.video.nzbdav/resources/lib/stream_proxy_handler_dispatch.py.orig`
around lines 356 - 359, Ensure the stream context acquired by
_get_stream_context(acquire=True) is released before returning from the
invalid-context branch when ctx is None or its mode is not "hls". Preserve the
existing 404 response, and keep valid HLS requests flowing through the normal
release path.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant