Let's assume there is a website with an API that supports the following REST call in which authenticated user Alice can send registered user Bob a message to his cell phone which he registered on our site (hypothetically speaking, for the sake of this example):
curl --header "Authorization: JWT $someTokenForAuthz" \
--header "Content-Type: application/json" \
--request POST \
--data '{"phone":"+43 123 456","msg":"some text"}'
http://example.com/text/send
Let's assume that we classify the phone number as sensitive (PII) data and let's assume, that the API returns the following response in case a phone number is submitted, which was not registered at the site:
{"error": {"code":404,"message":"Phone number not found"}}
Imagine Eve writing a script that iterates through the cell phone numbers +43 000 001 to +43 999 999 (ignoring real world phone number limitations). With the error code and after 1 000 000 iterations of her script, Eve has enumerated all numbers which are registered at the site and can e.g. target site users in a more specific way.
Is it a security issue to return an 404 HTTP error code when sensitive data like a cell phone number was not found in our system? What would be a better way in terms of error handling (as a backup strategy in case request limits/detection mechanisms that already in place might fail) to prevent such sensitive data discovery? A more general 401 - not authorized
error or something completely different?
400 Bad Request
. This is sortof a weird example though because users will probably become frustrated if the site rejects their messages without telling them why so you need to weigh the security vs the usability here. And ultimately an attacker will know if the message succeeded, and since wrong number is pretty much the only thing that could cause an error, I'm not sure you're hiding anything.Cookie:
orAuthorization:
header in this request. There may be more abuses you're not thinking about, e.g. if our attacker wants to harass a specific phone number with threatening messages.