T09 · Insecure Skill Coding Practices
- Location
references/encryption.md:94- Finding
Broken MTProto 2.0 AES key and IV derivation
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This is a documentation-only MTProto skill, but its security-critical examples contain multiple contradictory or incorrect protocol and cryptography instructions that could mislead implementation work.
Treat this skill as review-required before installation. It appears to be documentation-only and not locally dangerous by itself, but do not let an agent copy its MTProto crypto or parsing examples into production code without checking the official Telegram specification, known-good libraries, and independent cryptographic review.
references/encryption.md:94Broken MTProto 2.0 AES key and IV derivation
references/message-format.md:23Invalid Auth Key ID and message-key algorithms
references/handshake.md:156Incorrect MTProto handshake authentication and RSA construction
references/handshake.md:170Missing validation of the remote Diffie-Hellman public value
references/encryption.md:181Insecure padding generation and incorrect encrypted-message framing
references/tl-language.md:191Unchecked TL decoder slices allow remote process crashes
The documented auth_key_id derivation is wrong: it states an XOR with new_nonce, which does not match MTProto semantics and conflicts with the rest of the protocol description. A developer implementing this would derive incorrect key identifiers, leading to protocol breakage, message routing failures, and potentially incorrect trust in session state.
This documentation presents an incorrect auth_key_id derivation as 'CORRECT' and mandatory, while the sample only copies 4 bytes from SHA1 and leaves the remaining 4 bytes zero or undefined. In a protocol implementation guide, this can cause incompatible or ambiguous key identifiers, failed key lookup, and broken encrypted message handling across clients/servers; because implementers are likely to copy the sample verbatim, the skill context makes the issue more dangerous than a generic code snippet.
This guide presents custom encryption code and protocol-specific constructions in a way that could be copied into general-purpose applications without clear warnings against reuse. That is dangerous because developers may deploy unauthenticated, nonstandard crypto outside its narrow protocol context, where modern authenticated encryption is required and bespoke constructions are especially error-prone.
The document states that IGE 'provides integrity checking through error propagation,' which is misleading because error propagation is not authentication and does not prevent active tampering. Readers implementing this as written may omit a real MAC or authenticated-encryption check, enabling message modification, malleability, and forgery attacks in systems derived from the guide.
The temporary-key generation section uses SHA-1 in a derivation flow without clearly labeling it as legacy, protocol-bound behavior. Even if required for MTProto interoperability, presenting it without a strong warning can lead implementers to reuse SHA-1-based derivation in new systems, weakening cryptographic design choices and propagating obsolete practices.
The document claims to provide a complete MTProto 2.0 handshake, but its example uses RSA-OAEP for encrypting req_DH_params data, which is not MTProto's specified RSA processing. Implementers who follow this guidance will produce incompatible or noncompliant handshake code, and in security protocols, such deviations can cause failed interoperability or subtle security assumptions to break.
The document states that message IDs include a direction bit, but the generator implementation only combines a timestamp with a counter and never encodes direction. This inconsistency can lead to non-compliant or colliding message IDs, replay/ordering validation failures, and interoperability bugs in MTProto implementations, especially since this skill is explicitly intended to guide backend protocol development.
The documented TL string format says long strings use a 3-byte length form after the 0xfe marker, but the example emits four prefix bytes total: 0xfe plus three little-endian length bytes. In TL, this encoding is also subject to 4-byte alignment/padding rules; incorrect examples in a protocol implementation guide can cause interoperable parsers/encoders to be implemented incorrectly, leading to malformed message handling, desynchronization, parse failures, or unsafe downstream decoding assumptions in security-sensitive MTProto code.
The file gives contradictory descriptions of IGE error behavior, saying corruption garbles all remaining blocks while later claiming decryption resynchronizes after two blocks. In security documentation, such contradictions can cause incorrect reimplementation, faulty testing expectations, and unsafe error-handling logic around tampering or corruption.
This markdown file describes and exemplifies a client-server handshake that sends nonces, factored parameters, and encrypted payloads over the network, but it does not include any warning or disclosure about network transmission behavior. Under the markdown-file criteria for missing user warnings, descriptions should warn when behavior may affect privacy or system integrity.
No suspicious patterns detected.