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

Use unique iframe names based on unique domain #2955

Merged

Conversation

jridgewell
Copy link
Contributor

Browsers are weird. If an iframe has a name attribute, it’s window
will be cached. When you click a link, then go back, it will insert the
same src window into the iframe regardless of a different src.

Well, that hurts us since we generate a unique domain to load 3p
frames. We’ll continue to use an old domain’s window, even though the
src points to a new domain. Worse, when we post messages to the 3p
frame, we will send it with an origin parsed from the src attribute
even though that is not the real URL of the frame’s window.

Fixes #2943.

Browsers are weird. If an iframe has a `name` attribute, it’s window
will be cached. When you click a link, then go back, it will insert the
**same** src window into the iframe regardless of a different `src`.

Well, that hurts us since we generate a unique domain to load 3p
frames. We’ll continue to use an old domain’s window, even though the
src points to a new domain. Worse, when we post messages to the 3p
frame, we will send it with an origin parsed from the `src` attribute
even though that is not the real URL of the frame’s window.

Fixes ampproject#2943
@cramforce
Copy link
Member

Thanks! Please add a test.

@jridgewell
Copy link
Contributor Author

Added.

resetServiceForTesting(window, 'bootstrapBaseUrl');
resetCountForTesting();
const newName = getIframe(window, div).name;
expect(newName).not.to.equal(name);
Copy link
Member

Choose a reason for hiding this comment

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

It'd be really good to hard code the actual name string in a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@jridgewell jridgewell force-pushed the 3p-frame-postMessage-unique-domain branch 2 times, most recently from 677468e to da80c87 Compare April 21, 2016 01:17
@@ -238,4 +245,33 @@ describe('3p-frame', () => {
};
expect(getSubDomain(fakeWin)).to.equal('d-5670');
});

it.only('uses a unique name based on domain', () => {
Copy link
Member

Choose a reason for hiding this comment

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

.only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😔

@cramforce
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants