fix: Ensure that all API endpoint URLs are constructed safely. #544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#543 will be reverted before this PR is merged, as this achieves the same result (disallowing injection of path elements in serviceID fields).
As discussed in our chat today, this PR adds a
ToSafeURL
function which accepts a slice of strings that are used to construct the API endpoint URL. Each string is checked for unacceptable values (currently just..
) and passed throughurl.PathEscape
. The result is that if any components contains a 'special character' which could affect parsing or routing of the resulting URL, it will be URL-encoded for safety.I attempted to find all places where API endpoint URLs were being constructed from one or more components dynamically, but it is certainly possible that I missed some!
While this PR touches a lot of files, I find that the code is more readable now, as the URL-construction process isn't polluted by
Sprintf
format strings.