Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-14189): Ingore referrer kaltura.com in friendly iframe #870

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/common/utils/kaltura-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ function getReferrer(): string {
let referrer;
try {
referrer = window.parent.document.URL;
//Ignore referrer from friendly iframe that contains kaltura.com
if (referrer.toLowerCase().includes('kaltura.com')) {
throw new Error('ignoring referrer:' + referrer);
}
} catch (e) {
// unfriendly iframe

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/common/plugin/plugins-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ describe('getEncodedReferrer', () => {
sandbox.stub(window.parent.document, 'URL').get(() => {
return 'http://localhost:3000/?debugKalturaPlayer';
});
window.parent.document.URL.should.be.equal('http://localhost:3000/?debugKalturaPlayer');
getEncodedReferrer().should.be.equal('http%3A%2F%2Flocalhost%3A3000%2F%3FdebugKalturaPlayer');
});
});
45 changes: 45 additions & 0 deletions tests/e2e/common/utils/kaltura-params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
updateSessionIdInUrl
} from '../../../../src/common/utils/kaltura-params';
import { SessionIdGenerator } from '../../../../src/common/utils/session-id-generator';
const sandbox = sinon.createSandbox();

class Player {
public set sessionId(s) {
Expand Down Expand Up @@ -377,3 +378,47 @@ describe('addClientTag', () => {
source.url.should.be.equal('a/b/c/playmanifest/source?a&clientTag=html5:v' + __VERSION__);
});
});

describe('testReferrerLogic', () => {
before(() => {
window.originalRequestReferrer = undefined;
});

it('no referrer on parent', () => {
sandbox.stub(window, 'parent').get(() => undefined);
sandbox.stub(document, 'referrer').get(() => 'localRef');
getReferrer().should.equal('localRef');
});

it('referrer on parent', () => {
sandbox.stub(window, 'parent').get(() => {
return { document: { URL: 'parentRef' } };
});
getReferrer().should.equal('parentRef');
});

it('no referrer on parent and backend supplied referrer', () => {
sandbox.stub(window, 'parent').get(() => {
return { document: { URL: undefined } };
});
sandbox.stub(window, 'originalRequestReferrer').get(() => 'backendRef');
getReferrer().should.equal('backendRef');
});

it('if parent referrer contains kaltura.com and backend supplied referrer', () => {
sandbox.stub(window, 'parent').get(() => {
return { document: { URL: 'bla.kaltura.com' } };
});
sandbox.stub(window, 'originalRequestReferrer').get(() => 'test-kaltura.com');
getReferrer().should.equal('test-kaltura.com');
});

it('if parent referrer contains kaltura.com and backend does not supplied referrer', () => {
sandbox.stub(window, 'parent').get(() => {
return { document: { URL: 'bla.kaltura.com' } };
});
sandbox.stub(document, 'referrer').get(() => 'localRef');
sandbox.stub(window, 'originalRequestReferrer').get(() => undefined);
getReferrer().should.equal('localRef');
});
});
Loading