Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/engines/html5/media-source/adapters/fairplay-drm-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,18 @@
private _onWebkitKeyMessage(event: any): void {
this._logger.debug('Webkit key message triggered');
const message = event.message;
// WebkitMediaKeySession has attribute contentId (which is the mykeyid from playlist's skd://mykeyid)
const session = event.target;
const kid = session?.contentId;
const kidBase64 = btoa(kid);

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

The btoa() function expects a string input, but 'kid' could be undefined or null if session?.contentId is falsy. This will throw an error. Add validation: const kidBase64 = kid ? btoa(kid) : '';

Suggested change
const kidBase64 = btoa(kid);
const kidBase64 = kid ? btoa(kid) : '';

Copilot uses AI. Check for mistakes.

const request = new XMLHttpRequest();
request.responseType = 'arraybuffer';
this._eventManager.listenOnce(request, 'load', (e: Event) => this._licenseRequestLoaded(e));
const pkRequest: PKRequestObject = {
url: this._config.licenseUrl,
body: FairPlayDrmHandler._base64EncodeUint8Array(message),
headers: {}
headers: {'X-Kaltura-InitData': kidBase64} // pass the kid to uDRM
};
let requestFilterPromise;
const requestFilter = this._config.network.requestFilter;
Expand Down Expand Up @@ -265,9 +270,9 @@
}

public static _extractContentId(initData: Uint8Array): string {
const link = document.createElement('a');
link.href = FairPlayDrmHandler._arrayToString(initData);
return link.hostname;
const url = FairPlayDrmHandler._arrayToString(initData);
const hostname = url.slice(url.lastIndexOf("skd://")+6,url.length); // handle the skd://mykeyid format

Check warning on line 274 in src/engines/html5/media-source/adapters/fairplay-drm-handler.ts

View workflow job for this annotation

GitHub Actions / lint / running-tests (ubuntu-latest)

Strings must use singlequote
return hostname;
Comment on lines +274 to +275

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

If the URL doesn't contain 'skd://', lastIndexOf() returns -1, causing slice(-1+6, length) which would return the last 5 characters. Add validation: if (url.includes('skd://')) { return url.slice(url.lastIndexOf('skd://') + 6); } else { /* fallback logic */ }

Suggested change
const hostname = url.slice(url.lastIndexOf("skd://")+6,url.length); // handle the skd://mykeyid format
return hostname;
if (url.includes("skd://")) {
const hostname = url.slice(url.lastIndexOf("skd://") + 6); // handle the skd://mykeyid format
return hostname;
} else {
throw new Error("Invalid URL format: 'skd://' not found");
}

Copilot uses AI. Check for mistakes.
}

public static _arrayToString(array: Uint8Array): string {
Expand Down