`http_ece.decrypt` returns empty plaintext for header-only `aes128gcm` bodies without verifying any tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- cryptography, security
Rechercherichtung
Start in python/http_ece/__init__.py: parse_content_header() slices content[21 + id_len:] without checking the input length, and decrypt()'s record loop runs zero iterations on empty content. Run the reproduction in the issue to see b'' returned under a random key, and compare with nodejs/ece.js, which the report cites for the empty-plaintext case. Done means header-only and short-keyid bodies raise ECEException, encrypt(b"", version="aes128gcm") returns 38 octets, and the existing Python tests still pass.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
http_ece.decrypt() accepts header-only (or truncated-keyid) aes128gcm bodies and returns b"" under any key without running AES-GCM tag verification or checking a final-record delimiter. Conversely, http_ece.encrypt(b"", version="aes128gcm") emits only a 21-octet header with no authenticated record.
Distilled Summary
A header-only aes128gcm payload produces an empty record slice, so decrypt() executes zero iterations of its decryption loop and returns b"" without verifying any tag.
# Input: 21-byte header (salt + rs + idlen=0) with NO ciphertext records, any random key
# python/http_ece/__init__.py (buggy):
keyid, content = parse_content_header(body) # content == b"" (also if len(body) < 21 + id_len)
for i in range(0, len(content), chunk): # 0 iterations -> decrypt_record() & unpad() never run
...
return b"" # Observed: b"" (forged empty message accepted)
# Expected: raise ECEException("Message truncated") / header parse error;
# encrypt(b"") emits 21-byte header + 17-byte final record (0x02 + 16-byte GCM tag)
Privacy Impact
http_ece.decrypt() returns b"" for an aes128gcm body that consists only of the header (21 octets plus any keyid), or whose header announces a longer keyid than is present, without verifying any tag and regardless of the key. This is an integrity problem rather than a disclosure: confidentiality is not affected. Someone who can modify or inject the encrypted body in transit or at rest, without knowing the key, can make a receiver accept a forged empty message, or an emptied-out real message, as authentic, which matters where a successful return is treated as proof that the content came from a holder of the key. Non-empty forged content is still rejected.
Affected Component & Commit
- Repository:
web-push-libs/encrypted-content-encoding(https://github.com/web-push-libs/encrypted-content-encoding) - Commit:
75072478d56aab066cbbbb7fb75b6349426155cc(unchanged onmainatbf0906c8b108e0aedc9fe1b4df01a65fc12050c9) - File / Functions:
python/http_ece/__init__.py—parse_content_header(),decrypt(), andencrypt()
Vulnerability Details & Root Cause
parse_content_header()readsid_lenand sliceskeyid = content[21:21 + id_len]andcontent = content[21 + id_len:]without checking that the input actually contains21 + id_lenoctets. A header-only body, or one shorter than21 + id_len, yieldscontent == b""instead of raising a parse error.- In
decrypt(), thelen(content) % chunk == 0"Message truncated" check applies only to legacyaesgcm/aesgcm128versions. Foraes128gcm, an emptycontententersfor i in range(0, 0, chunk), executes zero iterations, never callsdecrypt_record()(AES-GCM tag verification) orunpad()(0x02final-record delimiter check), and returnsb"". - In
encrypt(),for i in range(0, end, chunk_size)withend == len(content) == 0emits no records, so empty plaintexts serialize to a bare header with no authenticated record.
RFC 8188 section 2 specifies that valid records carry a padding delimiter (0x02 on the final record) and a 16-octet authentication tag (though its framing sentence mentions "zero or more" records), sections 4.2 and 4.5 state that truncation is detectable and payload replacement without the key is impossible, and RFC 8291 section 4 requires every Web Push message to be encrypted with a single record whose 0x02 delimiter must be checked.
Other truncations are already rejected: dropping trailing records fails the 0x02 delimiter check in unpad(), dropping earlier non-final records shifts the nonce sequence number and fails AES-GCM verification (InvalidTag), a 16-octet tag-only fragment fails with InvalidTag, and a trailing fragment shorter than 16 octets raises an unhandled ValueError from the AES-GCM backend.
Preconditions & Threat Model
- An application decrypts
aes128gcmcontent withhttp_ece.decrypt()(such as a Web Push receiver or any RFC 8188 consumer) and treats a successful return as proof that the message was produced by a holder of the key. - An attacker who can inject or modify the encrypted body in transit or at rest (without knowing the key) replaces the body with a bare 21-octet header (any salt and record size) or a header whose
keyidlength exceeds the remaining bytes. decrypt()returnsb""instead of raising, causing the receiver to accept a forged empty message or an emptied-out real message as authentic. Non-empty forged payloads remain rejected by AES-GCM tag verification.
Minimal Reproduction
import os, struct
import http_ece as ece
header_only = os.urandom(16) + struct.pack("!L", 4096) + b"\x00"
print(ece.decrypt(header_only, key=os.urandom(16), version="aes128gcm"))
ct = ece.encrypt(b"", key=os.urandom(16), version="aes128gcm")
print(len(ct))
- Observed:
decrypt(header_only, ...)returnsb''under any random key (no exception);len(encrypt(b"", ...))is21(header only, no record). - Expected:
decrypt()raisesECEException("Message truncated")for header-only bodies andECEException("Could not parse the content header")whenlen(body) < 21 + id_len;encrypt(b"", ...)emits21 + 17 = 38octets (header plus 1-octet0x02delimiter and 16-octet GCM tag).
Impact
Message integrity is not enforced for empty aes128gcm payloads: unauthenticated header-only bodies decrypt successfully to b"" under any key. Applications that act on receipt of a (possibly empty) authenticated message, or treat successful decryption as an authenticity signal, can be fed forged empty messages or have real messages silently emptied. Confidentiality is not affected.
Suggested Fix
- In
parse_content_header(), raiseECEException("Could not parse the content header")when the input is shorter than21octets or shorter than21 + id_len. - In
decrypt(), rejectaes128gcmpayloads containing zero records withECEException("Message truncated"), and reject any record shorter than the minimum record length (delimiter + tag foraes128gcm, padding length + tag for legacy versions) withECEException("Message truncated")instead of letting the AES-GCM backend raiseValueError. - In
encrypt(), always emit at least one (final) record soencrypt(b"", version="aes128gcm")produces a 17-octet authenticated final record (0x02delimiter + 16-octet tag), matchingnodejs/ece.jsand RFC 8291 section 4. - Note the compatibility change: header-only 21-octet outputs emitted by older versions of
http_ece.encrypt(b"")will be rejected as truncated, and 16-octet (or 16-17-octet legacyaesgcm) short records will raiseECEException("Message truncated")instead ofInvalidTag.
Automated Privacy Audit Finding (AI-Generated): This finding is the output of a custom harness for privacy auditing. We ran the harness on this library because it is a production-grade library that processes privacy-sensitive data. I have reviewed and verified this finding, and I take responsibility for it. Feedback on the finding is very welcome. If you would prefer this library to be excluded from future automated audits, reply here and we will opt it out.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 36
- Forks
- 26
- Ø Merge
- 15 Min.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus web-push-libs/encrypted-content-encoding
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
-
feat(python): use secrets moduleEvtl. vergeben @Rotzbua hat das vor 22 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 54/100
web-push-libs/encrypted-content-encoding#97 · 2 Kommentare ·
-
`encrypt_data.json` file failing to pass http_ece/tests/test_ece.py::TestNode::test_(en|de)cryptOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 38/100
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
web-push-libs/encrypted-content-encoding#80 · 1 Reaktion ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 32/100
Alle Issues in web-push-libs/encrypted-content-encoding
Ähnliche Issues
-
area/frontend good first issue topic/intents
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
aws-samples/sample-collaborative-ai-dlc#1049 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
avniproject/avni-client#2268 ·
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's fileEvtl. vergeben @Beehtrix hat das heute übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
zilliztech/memsearch#907 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
we-promise/sure#6115 ·
Maintainer antworten meist innerhalb von 1 Tag
-
withImplementation leaves the temporary mock installed when its callback throws or rejectsEvtl. vergeben @Cynnamoroll hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 10 Tagen