What are the potential security risks of accessing content within an iframe using JavaScript?

When accessing content within an iframe using JavaScript, there is a potential security risk known as cross-origin scripting, where malicious code from the iframe could access sensitive information on the parent page or vice versa. To prevent this, you can implement a content security policy (CSP) that restricts the origins that can be loaded within the iframe.

<?php
header("Content-Security-Policy: frame-ancestors 'none';");
?>