← All issues

[4] Document.open() UAF via MutationObserver on Cross-Document Element

Severity: High | Component: WebCore DOM | 6767475

document.write 실행 중 firstDOMWindow에서 ASAN segfault가 관찰됩니다. 이는 document의 DOMWindow 연결에 대한 use-after-free 또는 null dereference에 부합하는 crash입니다. 트리거는 MutationObserver를 통해 web content에서 완전히 도달 가능합니다. 실제 fix는 별도 commit (300757@main, 이후 300886@main에서 reverted)에서 이루어졌으며, 이 commit은 regression test만 추가합니다. 따라서 diff 기반의 fix 메커니즘 분석에는 제약이 있습니다.

이 commit은 regression test만 추가하며, production 코드 변경은 포함되지 않습니다. 테스트는 DOMParser로 파싱된 document에서 element를 생성한 뒤, 메인 document에 document.open()을 호출하는 MutationObserver를 연결합니다. 이후 attribute를 설정해 observer를 발동시킵니다. 실제 fix는 300757@main에 반영되었다가 이후 300886@main에서 reverted되었습니다.

LayoutTests/fast/dom/Document/open-triggered-by-mutation-observer-on-element-from-a-parsed-doc-crash.html

+ const element = (new DOMParser()).parseFromString("<!DOCTYPE html><p>foo</p>","text/html").documentElement;
+ (new MutationObserver(_ => document.open())).observe(element, {attributes: true});
+ element.setAttribute("class", "bar");
+ document.body.innerHTML = "PASS if no crash.";

Cross-document element에 연결된 MutationObserver를 통한 re-entrant document.open() 호출이 실행 도중 calling document의 DOMWindow 연결을 무효화하는 패턴.

MutationObserver는 관찰 중인 DOM 노드가 변경될 때 알림을 전달하는 DOM API입니다. Observer는 microtask checkpoint에서 JavaScript callback을 실행합니다. document.open()은 현재 document를 초기화하고 쓰기 준비 상태로 전환합니다. 이 과정에서 browsing context의 DOMWindow와의 연결을 포함해 document 상태 전반이 해제되고 재초기화될 수 있습니다. DOMParser는 browsing context 없이 markup으로부터 새 Document를 생성합니다. 이렇게 생성된 document의 element에는 live frame이나 window가 없지만, 어느 document에 속한 MutationObserver든 해당 element를 관찰할 수 있습니다.

테스트 케이스를 통해 트리거가 드러납니다. DOMParser로 생성된 별도의 document에 속한 element에서 발동되는 MutationObserver callback 내부에서 document.open()을 호출하는 구조입니다. crash는 jsDocumentPrototypeFunction_write에서 호출된 WebCore::firstDOMWindow 내부에서 발생합니다. 이는 해당 context에서 document.open()이 실행되는 동안 document의 browsing context 또는 DOMWindow와의 연결이 무효화됨을 나타냅니다. 관찰 대상 element는 browsing context가 없는 parser 생성 document에 속합니다. attribute 변경 전달 중 mutation observer callback이 메인 document에 document.open()을 실행하면, call stack이 여전히 참조 중인 상태가 무효화될 가능성이 있습니다.

🔒

Explores the document lifecycle and memory model implications of this crash, and whether it could escalate beyond denial-of-service

더 확인하려면 구독해 주세요

🔒

Multiple re-entrancy audit patterns identified across document lifecycle operations, with concrete starting points for variant discovery

더 확인하려면 구독해 주세요