util.decorateRequest mechanism may edit user provided strings
| Copied from GoogleCloudPlatform/google-cloud-node#1891 | |
|---|---|
| @ofrobots December 19, 2016 20:15 | |
Environment details
Steps to reproduceThe request mechanism provided used by
Output:
It is surprising that the above example discovers french in the input string The above example is a bit contrived, but it is possible for user input to happen to contain the string I do like the convenience of the projectId placeholder string auto-replaced to the projectId during transit, but this leaves open the possibility that valid user input may get replaced accidentally. It might be a bit less elegant/convenient, but I think we should not use a mechanism that can accidentally edit user provided strings, however unlikely. | |
| @ofrobots February 10, 2017 22:34 | |
| Bump. Any traction on this? | |
| @stephenplusplus February 16, 2017 19:32 | |
The only thing I can think of is a more randomized string, e.g. {{projectId + uuid.v1()}}. Do you have any ideas? | |
| @bjwatson March 2, 2017 00:10 | |
@stephenplusplus Could we add an optional boolean that says to interpret the string literally, rather than doing auto-replace? Kind of like the difference between grep and fgrep? | |
Adding the approach here from an email from @ofrobots:
- implement Service.prototype.projectIdPromise. Ideally we should remove Service.prototype.projectId as it is asynchronously initialized. (GAX based libraries will need their analogue for this. It would have been nice if there was a common-gax, but that not existing, perhaps the generator needs to be modified. I don't fully understand how the generator works)
- anything that needs a projectId to be available should do
const promise = await this.projectIdPromiseor use a promise.then. This should be easy in libraries that are already using TypeScript, but that is not a strict requirement. - Get rid of all instances of the string {{projectId}} from across of all repos.
Closing based on age, and I think it was addressed. Feel free to reopen if not.