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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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');
});
});
37 changes: 37 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 @@
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,39 @@
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'}}});

Check failure on line 394 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Replace `return·{·document·:·{URL·:·'parentRef'}}` with `⏎······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}}});

Check failure on line 399 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Replace `return·{·document·:·{URL·:·undefined}}` with `⏎······return·{·document:·{·URL:·undefined·}·};⏎····`
sandbox.stub(window, 'originalRequestReferrer').get(() => "backendRef");

Check failure on line 400 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Replace `"backendRef"` with `'backendRef'`

Check warning on line 400 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Strings must use singlequote
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'}}});

Check failure on line 405 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Replace `return·{·document·:·{URL·:·'bla.kaltura.com'}}` with `⏎······return·{·document:·{·URL:·'bla.kaltura.com'·}·};⏎····`
sandbox.stub(window, 'originalRequestReferrer').get(() => "test-kaltura.com");

Check failure on line 406 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Replace `"test-kaltura.com"` with `'test-kaltura.com'`

Check warning on line 406 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Strings must use singlequote
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'}}});

Check failure on line 411 in tests/e2e/common/utils/kaltura-params.spec.ts

View workflow job for this annotation

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

Replace `return·{·document·:·{URL·:·'bla.kaltura.com'}}` with `⏎······return·{·document:·{·URL:·'bla.kaltura.com'·}·};⏎····`
sandbox.stub(document, 'referrer').get(() => 'localRef');
sandbox.stub(window, 'originalRequestReferrer').get(() => undefined);
getReferrer().should.equal('localRef');
});
});
Loading