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

Avoid creating an unbound number of atoms when deserializing #163

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

schnittchen
Copy link

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.

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. Since the endpoint is configurable, this PR should improve security.
@schnittchen
Copy link
Author

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

@etroynov
Copy link

etroynov commented Mar 7, 2022

Hi,

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

@schnittchen
Copy link
Author

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

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

Successfully merging this pull request may close these issues.

2 participants