nadia icon indicating copy to clipboard operation
nadia copied to clipboard

Avoid creating an unbound number of atoms when deserializing

Open schnittchen opened this issue 2 years ago • 3 comments

I have not checked that this does not break anything. The change assumes that

  • the structs have all been loaded (which is probably safe to assume) and so the atoms for the field names are already there
  • the subsequent parsing ignores keys which do not equal an expected struct field name (Probably true in all cases)
  • the Jason version that Nadia depends on supports the option used (did not check)

This could in theory use Jason.decode!(body keys: :atoms!) but that would crash when TG adds a field.

The code as-is is only secure when talking to a trusted endpoint. Using an untrusted endpoint exposes the user of the library to a potential DDOS attack by exhausting VM memory.

Since the endpoint is configurable, this PR should improve security. Additionally, users might be tempted to wire webhook payload parsing through the existing code, which would expose a security risk over the webhook endpoint.

schnittchen avatar Dec 25 '21 17:12 schnittchen

Sorry for the incomplete fix and the whitespace diff. Hastily opened this via the GH edit function...

schnittchen avatar Dec 25 '21 17:12 schnittchen

Hi,

@schnittchen Can you help me with it? please open PR here: https://github.com/etroynov/telegraph

etroynov avatar Mar 07 '22 19:03 etroynov

I've abandoned Nadia for https://github.com/schnittchen/cablegram

schnittchen avatar Mar 16 '22 12:03 schnittchen