Skip to content

fix(encryption): an encrypted object shaped like the Date marker is revived as a Date whatever its value #52

Closed

Description

@Upd4ting

EncryptionModifier stores a Date inside an encrypted value as { "type": "Date", "value": "<toUTCString>" } and date_decoder (src/modifiers/encryption.ts) turns every object with exactly the keys type and value, type === "Date", back into new Date(value.value) without checking what value.value is. A caller who stores such an object themselves gets a different value back.

Reproduction (built package, 0.1.11):

const lib = require("./dist/index.js");
class T extends lib.Table.with(lib.EncryptionModifier) {}
lib.Encrypted({ secretKey: "0123456789abcdef0123456789abcdef" })(T.prototype, "card");
const row = new T();
row.card = { type: "Date", value: 123 };
console.log(row.card instanceof Date, row.card); // true, 1970-01-01T00:00:00.123Z: the stored object is not returned

Expected: only the marker date_encoder writes (value a string toUTCString can have produced) is revived, and any other object comes back as stored. Fixing it is a behaviour change, so the 0.2.17 burn-down left it (six rows of encryption.ts:37-43 stay under the ratchet).

Activity

  1. Upd4ting commented on Nov 4, 2026

    @Upd4ting
    MemberAuthor

    Fixed by #57 (revive only the date marker the encoder writes), landed on main (921bf9d, the landed campaign/integration PR #87). Checked on main with the issue's repro: row.card = { type: 'Date', value: 123 } now reads back as the plain object, not a Date.

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