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

new line in key string will cause "Keys must not contain" error #3

Open
dannycochran opened this issue Nov 2, 2017 · 1 comment
Open

Comments

@dannycochran
Copy link
Contributor

dannycochran commented Nov 2, 2017

The following will result in a Firebase validation error for keys:

let myKey = `function () {
      foo;
  }`;
myKey = fkey.safe(myKey);
myDatabase.set(`somePath/${myKey}`, 'foobar');

The usage of newline doesn't seem documented anywhere by Firebase, however.

Update: It looks like the firebase docs actually do mention that ASCII control characters 0-31 or 127 are prohibited: https://firebase.google.com/docs/database/usage/limits

The regexp in this library should probably be updated to account for those characters.

@esprehn
Copy link

esprehn commented Jan 20, 2018

This library is escaping things to a custom encoding for example . becomes d<>, but it doesn't escape < or > so characters can become mangled when round tripped (ex. a user entering "<>d" would turn into ".") The library also needs to be updated to handle ascii control chars as discussed above.

A simpler approach is to use URI encoding. encodeURIComponent and decodeURIComponent exist in node and browsers. The only char that's not handled is ".", but since URI encoding can handle any char that can be converted to %2E. Decoding can always be done with decodeURIComponent.

const encode = (value) => encodeURIComponent(value).replace(/\./g, '%2E');
const decode = (value) => decodeURIComponent(value);

That's enough to replace this library without the bug mentioned here or the mangling of user input.

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

2 participants