Skip to content

DeprecationWarning: Buffer() is deprecated due to security and usability issues #2426

Closed

Description

@harry-chin

└─┬ [email protected]
└─┬ [email protected]
└── [email protected]

This issue is happening because of using old version of pg-types module.
Do you have a plan to update pgtypes to 3.x from 2.x?
The latest version of pg-types is using new version of postgres-bytea and this issue has been fixed there.

Activity

  1. brianc commented on Dec 3, 2020

    @brianc
    Owner

    Oh yes I need to upgrade. I know there are some backwards incompatible changes which is why I've waited so long. I think I should schedule a [email protected] upgrade for some time in January and make it a bundle of breaking changes. @charmander got any other breaking changes that come to mind? I'd like to deprecate the "query queue" concept in 9.0 - add a deprecation warning if you queue a query while another one is still in flight. Thoughts?

  2. charmander commented on Dec 3, 2020

    @charmander
    Collaborator

    @brianc All of that sounds good! BigInt becoming the default value type for BIGINT is also something pg-types might be about to get. If you’re looking to bundle more breaking changes (I guess it’s good for getting people to look at the changelog!), thoughts on these?

    We can open issues to discuss them if they sound worth talking about!

    Also, for pg-pool, there are breaking change ideas queued up, like returning client wrappers that stop working when they’re returned to the pool; those would also be waiting on a new major pg version eventually, so maybe they can be revisited too for this major.

  3. charmander commented on Dec 9, 2020

    @charmander
    Collaborator

    @vitaly-t Your “generic” package isn’t libpq-compatible. It’s MongoDB-compatible. release(true) is completely unrelated to what you quoted and I don’t feel like wasting time expanding on it for you.

  4. RichardBradley commented on Nov 14, 2022

    @RichardBradley

    Is there any update on this? We get this warning on all our Lambda invocations and it's quite noisy.

    How is the proposed upgrade to [email protected] progressing? Is there an issue I can follow for updates on that?

    Does anyone know of a workaround? Would it be practical to update the 2.x branch of pg-types to update its postgres-bytea without doing the full pg@9 update for node-postgres, if that is not expected soon?

  5. thmang82 commented on Jan 15, 2023

    @thmang82

    Any plans to fix this?
    Whenever BYTEA is used on a node:lts image (node 18), I get an error log. Not so nice :-(

  6. 70nyIT commented on May 16, 2024

    @70nyIT

    Want to do a bump in this. We've our monitor system flooded with console.error reporting this error, since we're using BYTEA a lot. Any chance to have this upgraded?

  7. danny-hunt commented on Jul 22, 2024

    @danny-hunt

    Hey this issue is causing crashes for me (although due to an obscure & annoying mesh of dependencies that isn't really pg's fault). There is a bug in some versions of node: nodejs/node#53075 that mean that the Buffer() deprecation warning instead crashes in WASM environments.

    I'm using vercel (whose current node version (20.15.X) is currently vulnerable to the above bug and neondatabase that uses pg as a dependency.

    Is there any idea when this might get addressed? I'll probably be looking for alternative solutions on my end anyway but thought it was worth bumping

  8. charmander commented on Jul 22, 2024

    @charmander
    Collaborator

    @danny-hunt You can add the newer version of pg-types as a dependency, then pass it to pg as the types property of the config.

  9. fedecastelli commented on Jul 26, 2024

    @fedecastelli

    Hi there!

    While I wait for a new release to fix how BYTEA is handled in node, I added these lines of code to my pg client initialization:

    import PG from 'pg';
    
    PG.types.setTypeParser(PG.types.builtins.BYTEA, function (value: string) {
      return value ? `0x${value.slice(2)}`.toLowerCase() : null;
    });

    This change prevents an error from being logged every time a BYTEA is read. I hope this helps!

  10. charmander commented on Jul 27, 2024

    @charmander
    Collaborator

    Also a good workaround. If you want to be compatible with the defaults in terms of producing a Buffer instead of a 0x… string, it’s

    PG.types.setTypeParser(PG.types.builtins.BYTEA, (value: string) => Buffer.from(value.slice(2), 'hex'));

    (Note that the default parser is compatible with PostgreSQL <9.0, but this one is not.)

  11. RichardBradley commented on Dec 16, 2025

    @RichardBradley

    Is there any update on this?

    We still get this warning on all our Lambda invocations and it's quite noisy.

    If it is too difficult to update pg-type, could this project perhaps add a workaround like fedecastelli suggested above? I'm hesitant to do that in my own code as I don't understand the risks and tradeoffs involved in changing how pg parses BYTEA (which is why I'm using a library!)

  12. charmander commented on Dec 16, 2025

    @charmander
    Collaborator

    @RichardBradley I’ll look into fixing it for pg 8 the right way1, by opening a pull request to create [email protected]; note that it might not be released in pg for a long time even if it is accepted [email protected]. But really, do this: #2426 (comment)

    pg won’t do it until the next major release because it includes breaking changes, but there’s no reason anyone creating new projects shouldn’t use the latest pg-types (and for non-new projects, no reason most people shouldn’t upgrade ahead of time).

    I’m not sure if pg-types has a changelog separate from its commits and from pg’s – it should probably get one – but I believe the breaking changes are:

    • removed Node 8 support (not a breaking change relative to pg 8, which requires Node ≥16)
    • added range type parsing (if you don’t use range types, no change)
    • removed date parsing (if you currently rely on the SQL date type being parsed to Date, you should fix that)
    • removed lib/arrayParser.js and the arrayParser export (you probably aren’t using this, but its functionality should be imported from postgres-array)
    • a few things related to binary parsers (pg doesn’t support binary mode yet, so you almost certainly aren’t using the binary parsers)

    Footnotes

    1. The workaround is not really possible to do at the library level without some level of breaking change because of how pg-types makes global mutable state part of its public API – specifically, a level of breaking change that’s not worth it for this backport. ↩

  13. charmander commented on Dec 17, 2025

    @charmander
    Collaborator

    [email protected] is out within the existing version constraints of pg 4.4.0 through 8.16.3 (latest) → pg-types 1.7.0 through 2.2.0 → postgres-bytea@~1.0.0 (thank you @bendrucker!), so all you need now is npm update postgres-bytea.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions