Skip to content

Node-RED 5.0.6 : regression in JSONata $moment #5924

Closed

Description

@uncle-fed

Current Behavior

Seems like the JSONata update (probably the JSONata surrounding code in a11abad) has caused regression in $moment().

This affects 5.0.5 and 5.0.6 Node-RED version.
Version 5.0.4 behaves correctly.

Expected Behavior

$moment().hour() should produce an integer, but now throws an error:

Invalid JSONata expression: Attempted to invoke a non-function.

Environment

  • Node-RED version: 5.0.5 and 5.0.4
  • Node.js version: 24.20.0
  • npm version: 11.19.0
  • Platform/OS: Raspberry Pi OS Bookworm

Activity

  1. changed the title [-]Node-RED 5.0.6[/-] [+]Node-RED 5.0.6 : regression in JSONata $moment[/+] on Sep 3, 2026
  2. knolleary commented on Sep 4, 2026

    @knolleary
    Member

    JSONata have made a breaking change to address a security issue. The fix for that issue is impacting precisely this use of JSONata in Node-RED.

    We are stuck between a rock (continuing shipping an older JSONata with documented Critical CVEs that block adoption) and a hard-place (take the CVE fix that changes behaviour).

    The CVE is regarding expressions being able to execute arbitrary code; but nothing that a Node-RED flow couldn't do for itself. I appreciate that's not really a defence, and it's good for JSONata to plug these gaps - its just a gap we relied on and we're currently left without a good solution.

    jsonata-js/jsonata#811

  3. uncle-fed commented on Sep 4, 2026

    @uncle-fed
    Author

    Would this be correct to say that "a few extra niceties" added by Node-RED on top of the JSONata core (for example $moment()) were possible because of the aforementioned "gap"? Or is the blast radius much wider than embedding an extra function/library?

    In other words, if Node-RED continued keeping up with JSONata (meaning, also accepting its breaking change as the new standard), how much of a breakage to Node-RED would this be, actually?

    I would be missing $moment, of course, but somehow we managed without it before it was injected into JSONata. What else would be gone if Node-RED accepted breaking changes?

    Also, what about this: https://docs.jsonata.org/embedding-extending ?

  4. knolleary commented on Sep 4, 2026

    @knolleary
    Member

    @uncle-fed it's a little more subtle.

    The embedding/extended things you link to is exactly how we are able to add the $moment function in the first place.

    What has changed is what properties of an Object JSONata will now let you access in an expression. If you're dealing with a pure JSON compatible 'thing', then nothing has changed. But when dealing with richer objects from JavaScript, the change impacts what you can access on those objects.

    The expression $moment() still works - it returns an instance of the Moment class. But $moment().hours() does not because JSONata will no longer access properties of that Moment class object. You could pass the result of $moment() to a Function node to call hours() on it - at which point, you may as well just use a Function node to do the whole thing.

    The main problem will be the blast radius is going to be unpredictable for end users who don't know about the distinction between pure JSON things, and JavaScript things.

  5. hardillb commented on Sep 4, 2026

    @hardillb
    Member

    I wonder if we can suggest a flag to re-enable the old behaviour?

  6. knolleary commented on Sep 4, 2026

    @knolleary
    Member

    @hardillb that is the most pragmatic solution in my opinion. There is a precedent for having a way to specify custom options to the engine in their 2.2.0 release - jsonata-js/jsonata#795

  7. uncle-fed commented on Sep 4, 2026

    @uncle-fed
    Author

    @knolleary

    You could pass the result of $moment() to a Function node to call hours() on it
    at which point, you may as well just use a Function node to do the whole thing

    That's what I have been doing with more complex logic that would require replacing multiple simple switch/change nodes.
    But JSONata has always been that "sweet spot" that would allow staying in the pure "basic nodes" domain.
    I'd often even force myself to use JSONata just to avoid putting the entire flow into a single JavaScript function node.
    Because what's the point of Node-RED then, right? :)

    Obviously, JSONata's true power and purpose lie in its JSON querying / transformation abilities, which JavaScript lacks.
    But somehow, we ended up using it for "all other purposes" ("all the wrong purposes"?), because it is embeddable in simple nodes, and adding $moment() is the best proof of that use.

    Now we are paying the price for "bending the original language purpose". Fun times.

    I've found these discussions, perhaps now seen in a slightly different light...

    https://discourse.nodered.org/t/change-node-enhancement-idea-add-javascript-function-as-a-change-option/67796
    https://discourse.nodered.org/t/feature-request-allow-one-liner-javascript-as-well-as-jsonata/82825/40

    I actually agree with you on all points that question / object the proposals.
    But mind wonders... so I guess the ideal solution is yet to come :-)

  8. knolleary commented on Sep 4, 2026

    @knolleary
    Member

    @uncle-fed thanks for the links. Bonsai look super interesting.

  9. dceejay commented on Sep 5, 2026

    @dceejay
    Member

    If a flag is possible then I would short term vote for that, with default new secure behaviour, which though breaking users would force them to accept/acknowledge vulnerability via the flag, but also to announce deprecation and move away from jsonata as per forum discussion re javascript.

  10. knolleary commented on Sep 8, 2026

    @knolleary
    Member

    We're going to patch JSONata in our next release to fix this.

  11. linked a pull request that will close this issueMigrate to patched JSONata #5933on Sep 8, 2026
  12. knolleary commented on Sep 8, 2026

    @knolleary
    Member

    Node-RED 5.0.7 is now available - $moment().hour() confirmed to be working again.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions