liveBook · Manning

Security

As explained in API Design Patterns

Security is the protection of systems and resources against unauthorized access, misuse, or exploitation.

Security protects API systems and resources from unauthorized discovery, access, misuse, and exploitation. Resource design, method behavior, and representation boundaries can either reduce or expose risk. section 6.2.5 section 7.2

Apply these security rules when designing APIs:

  • Use a sufficiently large, unpredictable key space instead of sequential identifiers, reducing the chance that probing discovers existing or misconfigured resources. section 6.2.5
  • Choose authorization errors consistently; returning different responses for nonexistent and unauthorized resources can reveal which resources exist. section 7.2
  • Separate highly restricted components, such as employee compensation, into a distinct resource or singleton sub-resource rather than exposing them with ordinary profile data. section 12.1.1

Protecting employee data

An employee API can expose nickname, hometown, and telephone number through the ordinary employee resource while keeping compensation behind a separately protected sub-resource. For unauthorized retrieval, a deliberately consistent error policy prevents callers from learning whether a protected record exists. section 12.1.1 section 7.2

How API Design Patterns covers it

How deep it goes
Explains key unpredictability, authorization-error ambiguity, and restricted sub-resources, but stops short of implementation code.
Examples
Uses sequential versus random identifiers, 404 versus 403 responses, and employee compensation separated from ordinary employee data.
What you can do after
Apply security by choosing unpredictable identifiers, consistent authorization responses, and separate resources for highly restricted data.
How it connects
Connects resource identification, access control, standard methods, and singleton sub-resources.

Also explained in

Compare how 28 books explain security →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.