TL;DR
Yes, malicious Javascript and browser extensions can steal certificates stored in your browser. This is a serious cyber security risk, but there are steps you can take to protect yourself. The main methods involve accessing the browser’s certificate store or intercepting network traffic during SSL/TLS handshakes.
How Certificates Can Be Stolen
- Accessing the Browser Certificate Store: Browsers store certificates for various purposes (website identification, client authentication). Malicious code can potentially access these stores.
- Javascript: Javascript running within a compromised website or injected via an extension can use browser APIs to list and export certificates.
- Browser Extensions: Extensions have broader permissions than regular web pages and can directly interact with the browser’s certificate management features. A rogue extension could extract certificates and send them to a remote server.
- Man-in-the-Middle (MitM) Attacks: Malicious extensions or code can intercept network traffic, including SSL/TLS handshakes.
- During the handshake process, certificates are exchanged. The malicious code can capture these certificates before they’re used for encryption.
- This is more common with poorly configured networks (e.g., using untrusted Wi-Fi) or when a compromised extension controls proxy settings.
Known Cases & Examples
While specific, widely publicised cases are often kept quiet to avoid further exploitation, several examples demonstrate the risk:
- Formjacking Extensions: Some extensions designed to steal form data have also been found with code capable of extracting certificates.
- Malicious Adware/Spyware Bundles: These bundles often include browser hijackers and extensions that can perform certificate theft as part of a wider range of malicious activities.
- Compromised Extension Developers: If an extension developer’s account is compromised, attackers can push updates containing malicious code to existing users.
Protecting Yourself – Step-by-Step Guide
- Keep Your Browser Updated: Updates often include security patches that address vulnerabilities exploited by malicious code.
- Chrome automatically updates, but check here to ensure you’re on the latest version.
- Firefox updates can be managed through Settings > General > Firefox Updates.
- Review Your Extensions: Regularly check the extensions you have installed.
- Chrome: chrome://extensions
- Firefox: about:addons
- Remove any extensions you don’t recognise or no longer need. Pay attention to permissions requested – be wary of extensions asking for excessive access.
- Use a Strong Antivirus/Anti-Malware Solution: A good security suite can detect and remove malicious code before it compromises your browser.
- Be Careful What You Click: Avoid downloading software from untrusted sources. Phishing attacks often lead to compromised websites that inject malicious Javascript.
- Enable HTTPS Everywhere: This extension forces secure connections whenever possible, reducing the risk of MitM attacks (although it doesn’t prevent certificate theft if the browser itself is compromised).
- Check Certificate Validity Regularly: While not a direct prevention method, regularly checking your installed certificates can help you identify suspicious entries.
- Windows: Open ‘Manage user certificates’ (search in Start Menu).
- macOS: Use Keychain Access.
- Consider a Hardware Security Key: For sensitive operations, using a hardware security key can protect your private keys from being stolen by browser-based malware.
Technical Details (For Advanced Users)
Malicious Javascript might use code similar to this (this is a simplified example and actual implementations will be more complex):
window.crypto.subtle.getKeyPair("RSA", false, ["exportKey"])
.then(function(keyPair) {
// Export the private key
const exportedPrivateKey = JSON.stringify(keyPair.privateKey);
console.log(exportedPrivateKey); // Send this to a remote server!
})
.catch(function(error) {
console.error("Error exporting key: ", error);
});
This code attempts to export the private key associated with an RSA key pair, which could then be sent to a malicious server.

