typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
393 stars 74 forks source link

fix: Escape user-supplied strings in URLs to prevent injection #211

Open LewisW opened 2 months ago

LewisW commented 2 months ago

Change Summary

Fixes #194 by escaping user-supplied strings in URLs. This fixes a potential vulnerability that gives a malicious actor the ability to delete parent collections by starting their ID with a hash (in cases where something user-supplied like a username, email etc. is used for the document ID/prefix).

It's also pretty common practice to use the # character in dynamodb keys, which is how we discovered this issue.

PR Checklist

kopertop commented 1 month ago

Just to add a +1 here, this also breaks when IDs have a / in them.

I would suggest the default should be to do the URL encoding in the library, and if you need an explicit opt-out for backwards compatibility you could add that, but certainly the default should be to encode them in the library (for new users like myself).