protect client using window ancestor root owner
All checks were successful
Deploy on Master Change / deploy (push) Successful in 36s

This commit is contained in:
2026-07-01 08:50:19 +07:00
parent c211741a30
commit 745e93d28d

View File

@@ -20,6 +20,7 @@ var (
procGetWindowThreadProcessId = user32.NewProc("GetWindowThreadProcessId")
procGetWindow = user32.NewProc("GetWindow")
procGetWindowLongW = user32.NewProc("GetWindowLongW")
procGetAncestor = user32.NewProc("GetAncestor")
dwmapi = syscall.NewLazyDLL("dwmapi.dll")
procDwmGetWindowAttribute = dwmapi.NewProc("DwmGetWindowAttribute")
@@ -141,6 +142,16 @@ var enumWindowsCallback = syscall.NewCallback(func(hwnd uintptr, lParam uintptr)
return 1
}
// Kiểm tra xem chủ sở hữu gốc (root owner) của cửa sổ này có thuộc về app ta hay không
rootHwnd, _, _ := procGetAncestor.Call(hwnd, 3) // GA_ROOTOWNER = 3
if rootHwnd != 0 {
var rootPid uint32
procGetWindowThreadProcessId.Call(rootHwnd, uintptr(unsafe.Pointer(&rootPid)))
if rootPid == uint32(os.Getpid()) {
return 1 // Cửa sổ thuộc về WebView2 / app của ta, bỏ qua không quét
}
}
title := getWindowText(hwnd)
if title == "" {
return 1