CVE-2022-39249
Executive Summary
CVE-2022-39249 is an authentication and integrity flaw in the Matrix Javascript SDK (matrix-js-sdk) affecting versions prior to 19.7.0. The vulnerability enables an attacker cooperating with a malicious homeserver to forge messages that appear to originate from another user, bypassing the cryptographic guarantees of the Matrix end-to-end encryption (E2EE) protocol. The root cause is an overly permissive key-forwarding strategy on the receiving client, which allows unverified devices to inject Megolm session keys and thereby decrypt or forge messages. Successful exploitation grants the attacker the ability to impersonate trusted contacts, deploy phishing messages within an encrypted channel, or manipulate message content while maintaining cryptographic plausibility. The attack has a CVSS base score of 7.5, reflecting high confidentiality and integrity impact though requiring coordination with a malicious homeserver, which limits the practical attack surface to scenarios where the homeserver itself is already compromised or hostile.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Technical Analysis
The Matrix protocol relies on the Megolm group encryption scheme to provide end-to-end encrypted messaging within rooms. To allow message history decryption across multiple devices, Matrix implements a key-sharing mechanism whereby Megolm session keys can be forwarded between devices. The matrix-js-sdk, prior to version 19.7.0, implemented a key-forwarding acceptance policy on the receiving end that was too permissive — it would accept forwarded session keys from unverified devices or without verifying that a key request had actually been issued by the local client.
The attack mechanism exploits the distinction between the protocol-level authenticity of a message and the cryptographic key used to decrypt it. In normal operation, a message that is successfully decrypted using a Megolm key is displayed as authentic. However, this assumption is invalidated when the decryption key itself originates from an untrusted source. If an attacker with control of a homeserver can forward a Megolm session key to a target client, that client will accept the key and decrypt messages using it. Since the client treats successful decryption as proof of sender authenticity, the forged message will be rendered as though it came from the legitimate sender. The only visible marker may be a grey shield indicator on some platforms, but the SDK did not force clients to present a clear warning for untrusted decryption keys.
The fix introduced in version 19.7.0 changes the default key-forwarding policy in two fundamental ways. First, the SDK will only accept forwarded keys in response to previously issued key requests — i.e., the client must have proactively asked for the key. Second, accepted forwarded keys are restricted to those coming from the client's own, verified devices. Additionally, the SDK now populates a trusted flag on the decrypted message, derived from whether the decryption key was received from a trusted source. Clients are expected to visually differentiate messages decrypted with trusted = false, for example, by displaying a warning. The description explicitly states that some platforms already grey-shield such messages, but the absence of a mandatory client-side decorator for untrusted keys left users on other platforms with no visual distinction.
The attack requires an active man-in-the-middle relationship between the attacker and the target's homeserver. In practice, this means the attacker must control or cooperate with the homeserver that serves the victim. The attack is not remotely triggerable without this precondition, which explains the relatively modest CVSS score of 7.5 despite the severity of the impact (message forgery and impersonation in end-to-end encrypted communication).
Insufficient technical detail is available regarding the exact code-level implementation of the key forwarding handler, the specific function names, or the message flow prior to the fix. The NVD description does not provide function-level or file-path-level specifics beyond the components described above. The vulnerability class is best characterized as an authentication bypass of the E2EE sender-authenticity guarantee, caused by an overly trusting key-acceptance policy.
Exploitation Scenarios
The attack chain for CVE-2022-39249 is multi-stage and depends on an adversary with control over — or cooperation from — a Matrix homeserver. The following attack chain is inferred strictly from the NVD description; no public exploit code or PoC has been identified as of the writing of this report.
Step 1 — Reconnaissance/Target Identification: The attacker first identifies the target's homeserver and the room in which the victim participates. Because the attack requires the attacker to supply a malicious Megolm session key, the attacker must be able to inject messages into the same encrypted room as the victim. This requires the attacker to be a member of the target room or to have compromised a homeserver that relays traffic for the target. Candidate targets are organizations relying on self-hosted Matrix homeservers (e.g., Synapse) where the attacker has already established a foothold at the infrastructure layer.
Step 2 — Triggering the Flaw: The attacker, cooperating with the malicious homeserver, constructs an encrypted message that claims to originate from the victim's legitimate contact. The attacker forwards a Megolm session key associated with this forged message to the victim's client. Because the matrix-js-sdk prior to 19.7.0 accepts forwarded keys without requiring a prior key request or verification of the sending device, the victim's client accepts the key and uses it to decrypt the message. The message decrypts successfully, so the client treats it as authentic.
Step 3 — Payload/Execution: The payload in this case is the forged message itself. Since the message is successfully decrypted and rendered, the victim sees content that appears to come from a trusted contact. The attacker can craft the message to include phishing links, malicious attachments, or instructions to perform sensitive actions (e.g., approve a payment, share credentials, download a file). The attacker may also leverage the forged message to escalate further social engineering attacks, relying on the victim's trust in the impersonated contact.
Step 4 — Post-Exploitation Impact: Successful exploitation undermines the trust foundation of Matrix E2EE. The victim will have received a message that is cryptographically valid, decryptable, and attributed to a trusted sender — but which is entirely attacker-controlled. This can lead to credential theft, malware delivery, or unauthorized business actions. The attack is subtle because there is no network-level anomaly: all traffic is legitimate Matrix protocol traffic. The only detection signal may be the presence of the grey shield or missing trust indicator, and only on platforms that implement this decorator.
An alternative exploitation path is the interception of legitimate message history: by forwarding the Megolm key to themselves, the attacker may decrypt previously transmitted room history that should have been inaccessible.
Impact Assessment
Business Impact: This vulnerability affects any organization that deploys a Matrix-based communication platform built on the Javascript SDK — most notably Element Web and other web-based Matrix clients. The impact is a wholesale undermining of the authenticity and integrity guarantees of end-to-end encrypted communications. In a sector where Matrix is chosen specifically for its security properties (e.g., government, defense, healthcare, finance), this vulnerability undermines the fundamental value proposition of the platform.
Affected Systems: All web-based Matrix clients using matrix-js-sdk versions prior to 19.7.0. This includes Element Web, custom in-house clients, and third-party clients embedding the SDK. The affected population is large but bounded: any deployment not updated to 19.7.0.
Blast Radius: The CVSS score of 7.5 (High) reflects the following subscores: Attack Vector: Network (AV:N), Attack Complexity: High (AC:H), Privileges Required: None (PR:N), User Interaction: Required (UI:R), Scope: Unchanged (S:U), Confidentiality Impact: High (C:H), Integrity Impact: High (I:H), Availability Impact: High (A:H). The high complexity and required user interaction reflect the prerequisite of a malicious homeserver and the fact that the victim must interact with the forged message for full impact. The EPSS score of 0.01027 (60.5th percentile) indicates a low-to-moderate probability of exploitation in the wild; the requirement for homeserver coordination likely suppresses exploitation frequency. The CVE is not in the CISA Known Exploited Vulnerabilities (KEV) catalog, and there is no evidence of public exploit code or known in-the-wild campaigns at the time of writing.
Detection Guidance
The following detection rules are designed to identify both the exploitation of CVE-2022-39249 and anomalous patterns that might indicate the presence of forged messages. Given that exploitation generates no obvious network anomaly — all activity occurs over standard Matrix protocol endpoints with valid TLS — these rules primarily focus on behavioral indicators: irregular key-forwarding patterns, large volumes of key requests from a single device, and the presence of messages with untrusted key flags in client logs.
Sigma Rule
title: Suspicious Matrix Megolm Key Forwarding Activity
id: 3b9a5d2e-8f4c-4f6a-9b2a-1c5d8e7f0a2b
status: experimental
description: Detects anomalous Megolm session key forwarding behavior consistent with CVE-2022-39249 exploitation. Focuses on key forwards from unverified devices or key forwards that arrive without a corresponding key request.
author: Valtersit Threat Intelligence
date: 2025/04/04
logsource:
category: application
product: matrix
service: client
detection:
selection_key_forward:
event_type: "m.room_key"
action: "forward"
device_verified: "false"
selection_unrequested:
event_type: "m.room_key_request"
request_id: "NULL"
selection_key_count:
key_count: "> 50"
condition: selection_key_forward or selection_unrequested or selection_key_count
level: high
falsepositives:
- Legitimate key re-sharing between user devices
- Key forwards initiated by user admin actions
tags:
- attack.t1557
- cve.2022.39249
YARA Rule
rule Matrix_Megolm_Unverified_Key_Forward {
meta:
author = "Valtersit Threat Intelligence"
description = "Detects log entries indicating Megolm key forwarding from unverified devices, potentially indicative of CVE-2022-39249 exploitation."
date = "2025-04-04"
cve = "CVE-2022-39249"
severity = "high"
strings:
$s1 = "m.room_key" ascii wide nocase
$s2 = "forward" ascii wide nocase
$s3 = "unverified" ascii wide nocase
$s4 = "key_request" ascii wide nocase
$s5 = "trusted=false" ascii wide nocase
$s6 = "device_verified" ascii wide nocase
condition:
(uint16(0) == 0x0A0D or uint16(0) == 0x0D0A) and
filesize < 1MB and
any of ($s1, $s2, $s3, $s4, $s5, $s6) and
2 of them
}
Suricata IDS Rule
Exploitation of CVE-2022-39249 occurs over TLS-encrypted WebSocket or long-polling connections to the Matrix homeserver. Network-level detection is therefore primarily limited to identifying anomalous Matrix protocol traffic patterns. The following rule identifies high-volume key-forward activity that may indicate bulk key harvesting.
alert http any any -> any any (msg:"Suspicious Matrix Key Forwarding Burst - CVE-2022-39249"; content:"m.room_key"; http_client_body; threshold:type both, track by_src, count 20, seconds 60; sid:202439249; rev:1; metadata:attack_target Client_Endpoint, created_at 2025_04_04, cve CVE-2022-39249;)
Note: This rule is inherently limited — it is placed at the network layer where it can only observe HTTP-level traffic before TLS encryption. For Matrix over WebSocket, inspect the upgrade request URI for /sync or /keys endpoints during the initial handshake phase, but post-TLS data will not be visible. Network detection should be considered a secondary layer beneath host-based log monitoring.
Elastic Detection
Elastic EQL query targeting Matrix client application logs or observability data where trusted = false flags appear alongside decryption events.
sequence by host.name with maxspan=5m
[ any where event.category == "application" and
message contains "m.room_key" and
message contains "forward" and
message contains "unverified" ]
[ any where event.category == "application" and
message contains "decrypt" and
message contains "trusted=false" ]
Splunk SPL Query
index=matrix_sdk sourcetype="matrix:client"
("m.room_key" OR "key_forward" OR "decrypted_message")
("trusted=false" OR "unverified" OR "device_unverified")
| eval cve="CVE-2022-39249"
| stats count by client_user, source_device, dest_device, _time
| where count > 5
| sort -count
| table _time, client_user, source_device, dest_device, count, cve
Wazuh OSSEC Rule
<group name="matrix,">
<rule id="100392" level="12">
<decoded_as>json</decoded_as>
<field name="event_type">m.room_key</field>
<field name="action">forward</field>
<field name="device_verified">false</field>
<description>Matrix: Megolm key forwarded from unverified device - possible CVE-2022-39249 exploitation</description>
<group>authentication_bypass, cve-2022-39249, t1557</group>
<mitre>
<id>T1557</id>
</mitre>
</rule>
<rule id="100101" level="8">
<decoded_as>json</decoded_as>
<field name="event_type">decrypted_message</field>
<field name="trusted">false</field>
<description>Matrix: Message decrypted with untrusted key - review for forgery indicators</description>
<group>integrity_violation, cve-2022-39249, t1557</group>
<mitre>
<id>T1557</id>
</mitre>
</rule>
</group>
Mitigation & Patch Guidance
Patch confidence is rated 3/4 — LIKELY — with two independent sources (the CNA and Red Hat Security Advisory [RHSA]) confirming the fix. The authoritative remediation is to upgrade matrix-js-sdk to version 19.7.0 or later.
1) Immediate Mitigations (if upgrade is not immediately possible):
- If self-hosting a Matrix homeserver, audit all users' device lists and remove unverified devices to reduce the key-forwarding attack surface.
- Manually review room keys that have been forwarded and invalidate any sessions suspected of containing untrusted keys.
- Instruct users to visually verify the grey shield indicator if their client platform displays it, and treat messages with such markings as untrusted.
- Disable cross-signing or verification bypass options in the client if they are not strictly required for operational workflows.
2) Patch/Upgrade Steps:
- Upgrade matrix-js-sdk to version 19.7.0 or later. For Element Web deployments, upgrade Element Web to a release that embeds a patched SDK version.
- For custom clients embedding matrix-js-sdk, rebuild and redeploy with the patched dependency.
- Verify the upgrade by checking that the SDK reports the patched version in client metadata or by confirming that key forwarding now requires a prior key request and verified device.
- Consult RHSA advisory for Red Hat–distributed packages of matrix-js-sdk and apply the corresponding RPM/deb updates if applicable.
3) Long-Term Hardening:
- Enforce mandatory device verification policies for all room participants.
- Deploy a client that implements the
trusted = falsewarning UI to ensure users receive visual confirmation of untrusted messages. - Enable server-side audit logs for key-forward events and monitor for anomalies such as bulk key requests or forwards from unverified devices.
- The NVD description notes that "those who trust your homeservers do not need a workaround." This is a useful policy guideline: organizations operating their own, trusted homeserver have reduced exposure. Fundamentally, the trust model of Matrix rests on the a user trusting their homeserver; this vulnerability erodes that trust boundary in multi-tenant or shared-homeserver environments.
References
- NVD Entry for CVE-2022-39249 — https://nvd.nist.gov/vuln/detail/CVE-2022-39249
- Matrix Security Advisory (CNA) — Matrix.org security disclosure for CVE-2022-39249
- Red Hat Security Advisory (RHSA) — Red Hat advisory covering matrix-js-sdk patched versions
- Matrix JS SDK GitHub Repository Release Notes for v19.7.0 — https://github.com/matrix-org/matrix-js-sdk (release notes for the patched version)
- CISA KEV Catalog — CVE-2022-39249 is not listed (no known exploited vulnerability status assigned)
As of the report date, there is no evidence of public exploit code, no known in-the-wild exploitation campaigns, and no CISA KEV listing for CVE-2022-39249. The EPSS score of 0.01027 (60.5th percentile) suggests low but non-zero likelihood of exploitation activity. Monitoring for future proof-of-concept releases is recommended, particularly within security research communities focused on Matrix protocol internals.
What is this? Security researchers use these exact search queries on Shodan.io (a search engine for internet-connected devices) to find vulnerable systems globally. You can copy these dorks to see if your organization's IP space is exposed.