Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONAta expression can be created that ends up in mutation of original input object #694

Open
adamscybot opened this issue May 9, 2024 · 0 comments

Comments

@adamscybot
Copy link
Contributor

As discussed here $clone is an internal that is used to ultimately provide an external interface that has no side effects.

$clone was put in the environment so it can be customised, but I'm not sure if this was intended just as a binding from the outside or if it was accepted it could be used inside expression.

One can manipulate the $clone method in order to manipulate the original input object. I feel the original input object should probably never be touched and it is surprising there is a way to get JSONata to alter the input object.

const expression = jsonata(`
 (
    $clone := function($a) {
      $a
    };
    (
      $ ~> | $ | {'newKey': 'this is added to the original input object!'} |
    )
  )
`)

const input = {
  existingKey: 'existing key',
}

console.log('ORIGINAL INPUT BEFORE EXPRESSION', input)
console.log('OUTPUT', await expression.evaluate(input))
console.log('ORIGINAL INPUT AFTER EXPRESSION', input)

In this example, the last console line does show that the newKey has actually been added to the original input object.

@adamscybot adamscybot changed the title JSONAta expression can be hacked to mutate original input object JSONAta expression can be created that ends up in mutation of original input object May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant