Detecting if there an element or iframe overlaid on top of my iframe to prevent clickjacking

Detecting if there an element or iframe overlaid on top of my iframe

I have an iframe that can be embedded inside any website based on the content security policy.

Is there a way for the my iframe code to detect if there is an element or iframe laid on top of it to prevent clickjacking?

I tried using the trackVisibility in the IntersectionObserver v2 API for this purpose. Let us assume for now that we are good with the fact that support on Chrome is good enough.

For simplicity of discussion, let us assume that the threshold is set to 1.0, so that the entire iframe has to be visible for isVisible to be true. Also, let us call my iframe as iframeGood and the overlaid malicious iframe to be iframeBad.

If the opacity of iframeBad is set to anything higher than 0, then the isVisible of the IntersectionObserver API shows the value as false.

However, if the opacity of the iframeBad is set to 0, then the isVisible of the IntersectionObserver API shows the value as true. Maybe this is intended since iframeGood is fully visible in this case, but it does not solve of the problem of clickjacking.

So is there a way to detecting if there an element or iframe overlaid on top of my iframe from within my iframe?

3

This is not possible from the iframe, but if you where to supply your clients with some JS that loads your iframe, then this could also use the InteresectionObserver API to test if another page element intersects your iframe. However you would then have to apply it to every element on the page and most likely use the MutationObserver API to check for elements being added late to the page as well.

This can all be done without adding any real overhead to the parent page, as these are pretty low level API that don’t really effect page performance, so long as you use them in an intelligent way.

Code would look roughly something like this

function coverObserver(options) {
  const onChange = options.onChange || (() => {})

  const observerOptions = {
    root: options.root,
    rootMargin: '0px',
    threshold: 0,
  }

  function callback(entries) {
    onChange(entries.map((entry) => entry.target))
  }

  const observer = new IntersectionObserver(callback, observerOptions)
  const observed = new WeakSet()

  return function (nodeList) {
    for (const node of nodeList) {
      if (node.nodeType !== Node.ELEMENT_NODE || observed.has(node)) continue

      observer.observe(node)
      observed.add(node)
    }
  }
}
coverObsever({
  root: myIframe,
  onChange: (coveringNodeList) => 
    console.log('Iframe covered by', ...coveringNodeList),
})(
  document.querySelectorAll('* :not(iframe)')
)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật