Skip to content

Iframe proxied requests may have invalid Referer header #6261

@KarolNov

Description

@KarolNov

What is your Test Scenario?

Currently I'm implementing third party integration which uses iframe to get their SDK. They use API keys and allow-list to either deny iframe request or to accept it. E2E tests using Testcafe are failing with the "deny" error whilst manual tests on the same environment work. Localhost host which Testcafe is using is whitelisted for the given API key. The issues seems to be connected to the request being sent with invalid header:
Here's how I found it

class 3rdPartySDKHook extends RequestHook {
    constructor() {
        const requestFilterRules = [/* regex filtering requests to only those iframe is performing */];
        super(requestFilterRules);
    }

    public async onRequest(event: any): Promise<void> {
        console.log(event.requestOptions.headers);
    }

    public async onResponse(): Promise<void> {
        // noop
    }
}

const hook = new 3rdPartySDKHook();

fixture`My fixture`
.page(TEST_URL).requestHooks(hook);

What is the Current behavior?

The Referer header is set to unproxied version of iframe src.

What is the Expected behavior?

The Referer header is set to url of page rendering iframe.

What is your web application and your TestCafe test code?

Working workaround:
class 3rdPartySDKHook extends RequestHook {
    constructor() {
        const requestFilterRules = [/* regex filtering requests to only those iframe is performing */];
        super(requestFilterRules);
    }

    public async onRequest(event: any): Promise<void> {
        event.requestOptions.headers.referer = TEST_URL;
    }

    public async onResponse(): Promise<void> {
        // noop
    }
}

const hook = new 3rdPartySDKHook();

fixture`My fixture`
.page(TEST_URL).requestHooks(hook);

Steps to Reproduce:

  1. Use iframe with src that uses ACL based on origin.
  2. See if the origin header gets set properly.

Your Environment details:

  • testcafe version: 1.9.4
  • node.js version: lts/erbium
  • command-line arguments: chrome --disable-web-security --allow-insecure-localhost --use-fake-device-for-media-stream --use-file-for-fake-audio-capture
  • browser name and version: Chrome 90
  • platform and version: macOS 11.2.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions