Agent Wranglers

API-43Required

Refuse plain HTTP on the API

Serve the API over HTTPS only. Refuse plain HTTP calls with an error instead of redirecting them.

How to do it

A redirect comes too late, because the token already crossed the network in clear text. Close port 80 for the API host, or answer every HTTP request with 403. Give the same answer whether the credential is valid or not, so the plain port can't test guesses. Revoke any key that arrives over plain HTTP, and rate-limit that port so nobody can revoke keys by sending guesses. Set up TLS itself as the website playbook's HTTPS rule describes.

Examples

nginx example

server {
  listen 80;
  server_name api.example.com;
  return 403;
}

How to check

curl -si http://api.example.com/orders fails to connect or answers 403. It never answers 301, 302, 307 or 308.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/api-security/api-https-only">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.