I have a code which looks like this
public async Task DeleteUser(string userId)
{
await httpClient.DeleteAsync($"/v1/api/users/{userId}");
}
The problem is that a malicious entry could delete something else than the expected user.
For example, if one user has many blog posts, a malicious entry could be userId="/v1/api/users/12394/posts/4", which would delete a blog post rather than removing the user.
Now, it seems that the Uri class has 3 differents escape methods. Uri.EscapeUriString, Uri.EscapeString and Uri.EscapeDataString.
However, the documentation around those and their differences either do not exist, or are really impossible to understand, requiring to read 3 RFCs to understand the purpose.
I remember I even saw additional methods (I think in a class called WebUtility) somewhere which also escape things in URL.
So what is the correct way of escaping a path segment?
EDIT:
I forgot HttpUtility.UrlEncode.