Aheho
Aheho

Reputation: 12821

http status code to use when server suspects posted form data is spam

Leaving aside the question of whether or not you should return "helpful" http status codes to someone who is spamming you, what would the appropriate http response code be in this situation. Let's say that you are scanning the form for blacklisted words and the submission has some.

Upvotes: 3

Views: 1828

Answers (2)

Bruno
Bruno

Reputation: 7221

For me for SCAM or SPAM fits best HTTP 451.

HTTP 451 Unavailable For Legal Reasons is a proposed standard error status code of the HTTP protocol to be displayed when the user requests a resource which cannot be served for legal reasons, such as a web page censored ... The RFC 7725 is specific that a 451 response does not indicate whether the resource exists but requests for it have been blocked, if the resource has been removed for legal reasons and no longer exists, or even if the resource has never existed, but any discussion of its topic has been legally forbidden.

Upvotes: 1

Barmar
Barmar

Reputation: 782785

403 Forbidden seems like the most appropriate code. The description from RFC 2616 says:

The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.

A better option may be the new 422 Unprocessable Entity code, defined in RFC 4918.

The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.

This blog post recommends it for situations like yours, where there's a semantic problem with the posted content, rather than a syntactic problem.

Upvotes: 5

Related Questions