동일한 출처 정책 및 iframe

마리코 코사카

이 Codelab에서는 iframe 내부 데이터에 액세스할 때 동일 출처 정책이 어떻게 작동하는지 알아봅니다.

설정: 동일한 출처 iframe이 있는 페이지

이 페이지는 동일한 출처에 iframe.html라는 iframe를 삽입합니다. 호스트와 iframe의 출처가 동일하므로 호스트 사이트에서 iframe 내부 데이터에 액세스하여 바람과 같은 비밀 메시지를 노출할 수 있습니다.

const iframe = document.getElementById('iframe');
const message = iframe.contentDocument.getElementById('message').innerText;

교차 출처 iframe으로 변경

iframesrchttps://other-iframe.glitch.me/(으)로 변경해 보세요. 호스트 페이지에서 계속 보안 비밀 메시지에 액세스할 수 있나요?

호스트와 삽입된 iframe의 출처가 동일하지 않으므로 데이터에 대한 액세스가 제한됩니다.