feat(wasm-demo): Add a section to inspect devolutions-crypto data#384
Conversation
The Inspect sections decodes a devolutions-crypto string and displays the header values and data of this object.
There was a problem hiding this comment.
Pull request overview
Adds an “Inspect (Debug)” page to the WASM demo so a devolutions-crypto base64 string can be decoded and its header + payload structure displayed for debugging.
Changes:
- Introduces a new standalone
InspectComponentthat base64-decodes input and parses/display header + payload fields. - Adds the
/inspectroute and a navigation link in the demo sidebar. - Adds dedicated HTML/CSS for the inspector UI (tables, badges, error styling).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| wrappers/wasm/demo/src/app/inspect/inspect.component.ts | Implements decode + header/payload parsing logic for the inspector view. |
| wrappers/wasm/demo/src/app/inspect/inspect.component.html | Renders input form plus parsed header/payload tables and error states. |
| wrappers/wasm/demo/src/app/inspect/inspect.component.css | Styles inspector tables, badges, hex display, and error presentation. |
| wrappers/wasm/demo/src/app/app.routes.ts | Registers the new /inspect route. |
| wrappers/wasm/demo/src/app/app.component.html | Adds a sidebar link to “Inspect (Debug)”. |
Comments suppressed due to low confidence (3)
wrappers/wasm/demo/src/app/inspect/inspect.component.ts:258
- For V2 asymmetric ciphertext,
payload.length < 56is too low: 56 bytes only covers pubkey+nonce and leaves zero bytes for the AEAD tag/ciphertext, which is not a valid XChaCha20-Poly1305 output. Require at least a 16-byte tag after the nonce (i.e., pubkey(32)+nonce(24)+tag(16) => 72 bytes).
// V2 (or Latest/0 which resolves to V2): XChaCha20-Poly1305
if (subtype === 2) {
// Asymmetric: EphemeralPubKey(32) + Nonce(24) + Ciphertext+Tag(var)
if (payload.length < 56) {
fields.push({
wrappers/wasm/demo/src/app/inspect/inspect.component.ts:271
ctWithTagcan be shorter than 16 bytes with the current validation, but the UI always reports the auth tag as 16 bytes. Either tighten the length validation to ensurectWithTag.length >= 16, or set the displayed tag size based ontag.length(and surface an error for malformed payloads) so the inspector doesn’t misreport offsets/sizes.
const ctWithTag = payload.slice(56);
const ct = ctWithTag.length > 16 ? ctWithTag.slice(0, ctWithTag.length - 16) : new Uint8Array(0);
const tag = ctWithTag.slice(Math.max(0, ctWithTag.length - 16));
wrappers/wasm/demo/src/app/inspect/inspect.component.ts:304
- For V2 symmetric ciphertext,
payload.length < 24is too permissive: 24 bytes is only the nonce with no ciphertext/tag. Since XChaCha20-Poly1305 always includes a 16-byte tag, validate that there are at least 16 bytes after the nonce (min 40 bytes total) to avoid showing empty ciphertext/tag fields as if they were valid.
} else {
// Symmetric (subtype None=0 or Symmetric=1): Nonce(24) + Ciphertext+Tag(var)
if (payload.length < 24) {
fields.push({
name: 'Error',
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const service: EncryptionServiceInner = await this.encryptionService.innerModule; | ||
| const input: string = this.debugForm.value.input?.trim(); | ||
| if (!input) { | ||
| return; |
|
Codex (@codex) review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f35e823610
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| ): PayloadField[] { | ||
| const fields: PayloadField[] = []; | ||
|
|
||
| if (version === 1) { |
There was a problem hiding this comment.
Stop decoding unknown ciphertext versions as V2
parseCiphertextPayload only special-cases version === 1 and then falls through to V2 parsing for every other value, so malformed or future-version ciphertexts are rendered as if they were valid V2 structures. The core library treats unsupported versions as UnknownVersion (rather than coercing them to V2), so this produces misleading inspect output instead of surfacing that the version is unsupported.
Useful? React with 👍 / 👎.
| }); | ||
| } else { | ||
| // Symmetric (subtype None=0 or Symmetric=1): Nonce(24) + Ciphertext+Tag(var) | ||
| if (payload.length < 24) { |
There was a problem hiding this comment.
Tighten V2 payload length validation before field splitting
The V2 symmetric/asymmetric length guards are too permissive (< 24 and < 56), so payloads that are structurally invalid can still be split into nonce/ciphertext/tag fields and shown as if they were well-formed. In the core parser, these payloads must be longer than nonce-only data (and asymmetric wraps that same constraint after the 32-byte key), so the current checks can misclassify invalid blobs during inspection.
Useful? React with 👍 / 👎.
e8f1cfe
into
master
The Inspect sections decodes a devolutions-crypto string and displays the header values and data of this object.