hapijs / iron

Encapsulated tokens (encrypted and mac'ed objects)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined values are removed from seal when stringified

vvo opened this issue · comments

Support plan

  • which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 12.16.1
  • module version: 6.0.0
  • environment (e.g. node, browser, native): noe
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

How can we help?

Hi there, when you try to seal an object like {id: undefined, admin: true} and then unseal the resulting sealed object then you get back {admin: true}. All undefined values are removed (and their keys) from the sealed object since we use JSON.stringify in @hapi/iron.

I only want to see if you'd be interested in keeping those values instead of removing them. Why? I have spent some time trying to understand why some of my properties were disappearing from the sealed objects to discover that it's because we use JSON.stringify in @hapi/iron. If it had sent me {id: undefined, admin: true} then I would have identified the issue earlier.

In general, we could say that we should serialize the data as close as possible to what the user sent to avoid surprises. But at the same time I am definitely fine if we keep JSON.stringify. In the end, the bug was on my side at first, then the behavior of @hapi/json was unexcepted from me but that's it.

Thanks

I would just document it and leave it as is. If this is an important use case, we can allow you to provide your own stringify() but this has never come up since the module was first published.