GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto Cipher/Decipher validation issues · Issue #45189 · nodejs/node

crypto Cipher/Decipher validation issues #45189

New issue
Copy link
New issue
Copy link
Closed
Closed
crypto Cipher/Decipher validation issues#45189
Copy link
Labels
confirmed-bugIssues and PRs for confirmed bugs.cryptoIssues and PRs related to the crypto subsystem.

Description

@targos
targos
opened on Oct 26, 2022
Issue body actions

This also affects Decipher methods.

Here's an example:

const { createCipheriv, randomBytes } = require('crypto');

const cipher = createCipheriv('aes-256-cbc', randomBytes(32), randomBytes(16));

cipher.update('test', 'utf-8', 'bad');

Gives an internal assertion:

Error [ERR_INTERNAL_ASSERTION]: Cannot change encoding
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

final has the same issue:

const { createCipheriv, randomBytes } = require('crypto');

const cipher = createCipheriv('aes-256-cbc', randomBytes(32), randomBytes(16));

cipher.update('test', 'utf-8', 'utf-8');
cipher.final('bad');

Other issue:

const { createCipheriv, randomBytes } = require('crypto');

const cipher = createCipheriv('aes-256-cbc', randomBytes(32), randomBytes(16));

let result = cipher.update('test', 'bad', 'hex');
result += cipher.final('hex');
console.log(result);

Gives no error at all for the wrong input encoding.

@nodejs/crypto

Activity

  1. targos
    added
    confirmed-bugIssues and PRs for confirmed bugs.
    cryptoIssues and PRs related to the crypto subsystem.
    on Oct 26, 2022
  2. kivancbilen commented on Dec 1, 2022

    @kivancbilen
    kivancbilen
    on Dec 1, 2022
    More actions

    Would it make sense to introduce a new error like ERR_CRYPTO_UNKNOWN_ENCODING with a message Unknown encoding {wrong encoding name}?

  3. panva commented on Jan 6, 2023

    @panva
    panva
    on Jan 6, 2023
    Member
    More actions

    I'm afraid the last mentioned "other issue" is also present in Sign , Verify, Hash, Hmac, and the like. I also suspect hard validating may be breaking for a lot of legacy applications.

    I suggest to deal with the first two in #45990 and leaving the inputEncoding validation to a separate PR and CITGM to decide whether it's worth fixing or not.

    Also refs: #31766

  4. nodejs-github-bot
    added a commit that references this issue on Jan 17, 2023

    crypto: add cipher update/final methods encoding validation

    5a7d4a7
  5. RafaelGSS
    added a commit that references this issue on Jan 20, 2023

    crypto: add cipher update/final methods encoding validation

    78be87b
  6. juanarbol
    added 2 commits that reference this issue on Jan 26, 2023

    crypto: add cipher update/final methods encoding validation

    5f6aab3

    crypto: add cipher update/final methods encoding validation

    a558774
  7. nodejs-github-bot
    added a commit that references this issue on Sep 30, 2026

    crypto: validate inputEncoding in Cipher/Decipher update

    127f79a
  8. nodejs-github-bot
    closed this as completedin 127f79aon Sep 30, 2026
  9. pull
    added 3 commits that reference this issue on Sep 30, 2026

    crypto: validate update input encodings

    6b8001d

    crypto: validate digest output encodings

    718f044

    test: fix fs write encoding coverage

    822e8ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.cryptoIssues and PRs related to the crypto subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.