Blog | G5 Cyber Security

Website Keystroke Tracking: What’s Possible?

TL;DR

Websites cannot directly track keystrokes outside of their own input fields (like text boxes). Modern browsers prevent this for security reasons. However, they can monitor what you type *within* those fields and potentially detect some browser shortcuts if specifically coded to do so.

Understanding the Limitations

The ability of a website to track keystrokes depends heavily on where you’re typing and how your browser is configured. Here’s a breakdown:

1. Tracking Keystrokes *Within* Website Forms

  1. How it works: Websites can use JavaScript to listen for keyboard events (keydown, keyup, keypress) within their input fields (e.g., text boxes, search bars).
  2. Example Code:
    document.getElementById('myInput').addEventListener('keydown', function(event) {
      console.log('Key pressed:', event.key);
    });

    This code snippet listens for any key press within an element with the ID ‘myInput’ and logs the pressed key to the browser console.

  3. What they can see: The characters you type, special keys like Shift, Ctrl, Alt, etc., when focused on a form field.
  4. Limitations: They only capture data within their own fields. They cannot see what you’re typing in other applications or even outside of the current browser tab.

2. Tracking Browser Shortcuts/Keybinds

  1. How it works: Websites can attempt to detect certain browser shortcuts (e.g., Ctrl+C for copy, Ctrl+V for paste) using JavaScript event listeners. However, this is becoming increasingly difficult due to browser security measures.
  2. Example Code:
    document.addEventListener('keydown', function(event) {
      if (event.ctrlKey && event.key === 'c') {
        console.log('Ctrl+C pressed!');
      }
    });

    This code attempts to detect when Ctrl+C is pressed globally within the browser window.

  3. Limitations:
    • Browser restrictions: Modern browsers often block or limit access to global keyboard events for security reasons.
    • User control: Users can disable JavaScript or use browser extensions to prevent tracking.
    • Inconsistency: Shortcut detection varies significantly between browsers and operating systems.

3. OS-Level Keylogging

Websites cannot directly access or track keystrokes at the operating system (OS) level through standard web technologies like JavaScript. This would be a major security breach.

4. Malware and Browser Extensions

  1. The risk: If your computer is infected with malware or you have malicious browser extensions installed, they could potentially log keystrokes system-wide.
  2. Protection:
    • Use a reputable antivirus program and keep it updated.
    • Be careful when installing browser extensions – only install those from trusted sources.
    • Regularly scan your computer for malware.

5. How to Protect Yourself

  1. Use strong passwords: Even if a website captures some keystrokes, strong and unique passwords make it harder for attackers to compromise your accounts.
  2. Be cautious of phishing attacks: Phishing websites may try to trick you into entering sensitive information in fake forms.
  3. Keep your browser updated: Browser updates often include security patches that address vulnerabilities.
  4. Use a password manager: Password managers can automatically fill in passwords, reducing the risk of keystroke logging.
Exit mobile version