I am working on a web development project with HTML, React, JavaScript and CSS.
We want to load an external web page in an iframe. We have the URL for that external resource.
Code snippet 1: the URL is hard-coded
<iframe src="myExternalResourceUrl" title="description"></iframe>
Code snippet 2: the URL is dynamically passed in as a variable
const _externalLink = "myExternalResourceUrl";
<iframe src={_externalLink} title="description"></iframe>
Code snippet 1 works and snippet 2 does not work. It gives security errors in the console.
because an ancestor violates the following Content Security Policy directive: "frame-
ancestors 'self:
What's the difference between the two snippets from a security perspective? Is this something that the external resource can control?