Skip to content

Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks #51064

Closed

Description

@qiaohang

Preflight Checklist

Electron Version

41.2.0, 36.4.0

What operating system(s) are you using?

Windows

Operating System Version

Windows 11 26100

What arch are you using?

x64

Last Known Working Electron version

No response

Does the issue also appear in Chromium / Google Chrome?

No

Expected Behavior

NativeWindowViews::SetForwardMouseMessages function unhooks the global mouse hook using UnhookWindowsHookEx(mouse_hook_) when the forwarding_windows_ set becomes empty. It should verify the return value of UnhookWindowsHookEx

Actual Behavior

If UnhookWindowsHookEx fails (returns FALSE), the existing hook remains active in the system. Because mouse_hook_ is reset to nullptr regardless of success, subsequent calls to SetForwardMouseMessages(true) will evaluate if (!mouse_hook_) as true. This causes SetWindowsHookEx to be called again, installing an additional, duplicate mouse hook

Testcase Gist URL

No response

Additional Information

No response

Activity

  1. added theissue type on Apr 15, 2026
  2. electron-issue-triage commented on Apr 15, 2026

    @electron-issue-triage
  3. changed the title [-]Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/-] [+][Windows] Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/+] on Apr 15, 2026
  4. changed the title [-][Windows] Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/-] [+]Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/+] on Apr 15, 2026
  5. removed
    blocked/need-info ❌
    on Apr 15, 2026
  6. moved this to 👀 Unsorted Items in 41-x-yon Apr 15, 2026
  7. nikwen commented on Apr 15, 2026

    @nikwen
    Member

    Thanks for reporting!

    Would you be able to download Electron Fiddle, use it to create a small sample app that allows maintainers to reproduce this issue, and upload it as a GitHub gist from Fiddle?

  8. added
    blocked/need-repro
    on Apr 15, 2026
  9. electron-issue-triage commented on Apr 15, 2026

    @electron-issue-triage

    Hello @qiaohang. Thanks for reporting this and helping to make Electron better!

    Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

    Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

    Now adding the blocked/need-repro Needs a test case to reproduce the bug label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

  10. qiaohang commented on Apr 15, 2026

    @qiaohang
    Author

    Thanks for reporting!

    Would you be able to download Electron Fiddle, use it to create a small sample app that allows maintainers to reproduce this issue, and upload it as a GitHub gist from Fiddle?

    This issue is not consistently reproducible and tends to occur more easily on certain machines, though not on mine. Through code review and checking the API documentation for UnhookWindowsHookEx it was found that the return value of UnhookWindowsHookEx is not being checked.

  11. removed
    blocked/need-repro
    on Apr 15, 2026
  12. moved this from 👀 Unsorted Items to 👍 Does Not Block Stable in 41-x-yon Apr 15, 2026
  13. added 6 commits that reference this issue on Apr 16, 2026
    94454e1
    9ea0694
    bbd21ab
    bdc2c7c
    990ef04
    84f4a00
  14. added a commit that references this issue on Apr 30, 2026
    d0612e2
  15. added 2 commits that reference this issue on Apr 30, 2026
    f04ad9d
    6037d59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions