If you're concerned about security, note that sites can respond to requests and specify that they should not be embedded by requesting user agents in iframes. See the X-Frame-Options
HTTP header and frame-ancestors
Content Security Policy.
If you're instead interested in protecting the embedder (rather than the embeddee), see the allow
attribute of <iframe>
s.
The main security mechanism you care about is the Same-Origin Policy, which basically is that resources from different origins should not have access to one another. If you want to read more about it, you may be interested in the MDN page and the Wikipedia page on the subject.
There are ways for resources from different origins to cooperate (basically both giving each other consent to communicate), such as window.postMessage
. If the iframe page is from the same origin as the parent frame, then yes, the parent frame can "reach in" to the DOM of the child frame. Ex. Get element from within an iFrame.
A user operating a user agent (such as a browser) can still use tools provided by the user agent to inspect the resources of the sites, but that's not as much of a security concern- barring the user shooting themselves in the foot by very intentionally being a side-channel for information from one origin's resource to get to another's. Ex. copy and pasting things from browser devtools.