Preserve existing query string when adding HLS delivery directives - #7969
Merged
robwalch merged 2 commits intoAug 7, 2026
Conversation
Mutating url.searchParams and then reading url.href re-serializes the entire query using application/x-www-form-urlencoded rules. That percent-encodes `~`, `=` and `/` in query parameters hls.js was not asked to touch. Signed CDN URLs carry those characters verbatim and validate the request byte-for-byte, so every playlist reload that adds _HLS_msn, _HLS_part or _HLS_skip is rejected with 403 and live playback stalls. Build the query as text instead, filtering out any directive already present so repeated reloads replace rather than duplicate. video-dev#3787 addressed the parameter reordering half of video-dev#3786 by dropping searchParams.sort(), but the re-encoding remained.
robwalch
reviewed
Aug 6, 2026
…rams.set Extracts the query-string-preserving logic from HlsUrlParameters.addDirectives into a setQueryParam export in utils/url-tools and uses it everywhere _HLS_ parameters are appended (content-steering-controller, interstitial-event, interstitial-asset-list). Adds a lint rule disallowing URLSearchParams.set, which re-encodes the whole query string and breaks signed CDN tokens. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
robwalch
approved these changes
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR will...
Stop
HlsUrlParameters.addDirectivesfrom re-encoding query parameters it did not add, so signed playlist URLs survive Playlist Delta Update and blocking reload requests.Why is this Pull Request needed?
addDirectivessets_HLS_msn/_HLS_part/_HLS_skipthroughurl.searchParams. Readingurl.hrefafterwards re-serializes the whole query using application/x-www-form-urlencoded rules, so characters that are perfectly legal in a query (~,=,/) come back percent-encoded in parameters hls.js never touched.Given a playlist URL carrying a signed token:
a delta update request currently becomes:
CDNs that sign URLs compare the token byte-for-byte, so the request is rejected with 403 and live playback stalls on the first reload. Akamai tokens are the common case; CloudFront is affected too, since its URL-safe base64 maps
/to~, putting~in everyPolicyandSignaturevalue. Native HLS implementations do not rewrite the URL, so affected streams play fine outside hls.js.With this change the request keeps the token intact:
#3786 reported this in 2021. #3787 fixed the parameter reordering half by removing
searchParams.sort(), buturl.searchParams.set()still forces a full re-serialization whenhrefis read, so the re-encoding half remained.Are there any points in the code the reviewer needs to double check?
searchParams.set(). The one behavioural difference is position: a replaced directive moves to the end of the query instead of keeping its original slot. SincesearchParams.sort()was removed in Direct set SearchParams on URL and remove sort. #3787, query order is not normalized either way.url.search = ...not percent-encoding~,=,/or*, as those are outside the URL query percent-encode set. Worth a second pair of eyes.HlsSkip.Nois the empty string and stays falsy, andmsn/partof0are still emitted. Both are covered by tests.Resolves issues:
Completes the fix for #3786, partially addressed by #3787.
Checklist