@@ -8,7 +8,7 @@ description: "Implement robust security measures in your API to protect sensitiv
88Creating an API is like opening a door to the outside world. Who is allowed
99through, what they can carry, and where they're allowed to go is incredibly
1010important. In this guide we'll see how design choices made early on impact the
11- security of an API once it's built.
11+ security of an API once it's built.
1212
1313Many API security problems come down to coding errors or misconfigured
1414infrastructure, but this guide focuses more on the foundational API design
@@ -48,10 +48,10 @@ decisions can make or break an API's defenses before it's even built.
4848** Every API consumer should only have access to what they need and nothing more.**
4949
5050Imagine designing an API for an e-commerce platform. A customer should be
51- able to view their order history, but not other customers' orders.
51+ able to view their order history, but not other customers' orders.
5252
5353Similarly, a "staff" user might need access to refund functionality but shouldn't
54- necessarily see sensitive payment details.
54+ necessarily see sensitive payment details.
5555
5656** What Could Go Wrong** : Failure to verify this could lead
5757to Insecure Direct Object References (IDOR), a common flaw where attackers can
@@ -67,7 +67,7 @@ Authorization: Bearer {access_token}
6767```
6868
6969The application should verify that the ` orderId ` belongs to the authenticated
70- user, unless the user has a role like ` admin ` .
70+ user, unless the user has a role like ` admin ` .
7171
7272Refund logic and payment details can be split onto their own endpoints:
7373
@@ -83,7 +83,7 @@ Authorization: Bearer {admin_access_token}
8383
8484This allows staff handle refunds, but does not leak sensitive credit card
8585information to as many people within the company, whilst still making it
86- possible to escalate customer problems to a higher access user.
86+ possible to escalate customer problems to a higher access user.
8787
8888Better yet, ** the payments collection is not even on the API** , it's something only
8989viewable in an admin backend system thats protected with a firewall and VPN.
@@ -94,17 +94,17 @@ viewable in an admin backend system thats protected with a firewall and VPN.
9494"private".**
9595
9696Any incoming API traffic could be compromised in some way, even if it's
97- considered to be a trusted source.
97+ considered to be a trusted source.
9898
9999An API could suddenly become public: either intentionally when infrastructure
100100teams move things around, or accidentally when somebody de-compiles an iOS
101- application or sniffs traffic to find an API that people thought was hidden.
101+ application or sniffs traffic to find an API that people thought was hidden.
102102
103103Even if an API is firewalled off from public traffic, another API or service
104104could have been hacked giving them access to the protected API.
105105
106106It's best to treat everyone with suspicion, and validate all inputs as strictly
107- as possible.
107+ as possible.
108108
109109** What Could Go Wrong** : Malicious data could be introduced, or private
110110information leaked, leading to any number of issues. People could delete invoice
@@ -113,13 +113,13 @@ wrong person. They could change passwords for users so they can log in as them
113113to access information and processes not even available in the API.
114114
115115** Design Decision** : Set strict rules for which properties are editable, which
116- can be returned, and set strict validation rules for these properties.
116+ can be returned, and set strict validation rules for these properties.
117117
118118This can be described in OpenAPI early on utilizing ` readOnly ` , ` writeOnly ` ,
119119` required ` , setting ` additionalProperties: false ` . [ Learn more about
120- additionalProperties] ( https://www.speakeasy.com/guides/openapi /additionalproperties ) .
120+ additionalProperties] ( https://www.speakeasy.com/docs/sdks/customize/data-model /additionalproperties ) .
121121This means when the API is developed the OpenAPI can be used for integration
122- testing to poke and prod to see if extra properties can sneak though.
122+ testing to poke and prod to see if extra properties can sneak though.
123123
124124Comical examples of this was somebody hacking GitHub and Rails to update the
125125` created_at ` date to have the year 3012. This attack is known as Bender from the
@@ -153,7 +153,7 @@ Authorization: Bearer my-secret-key
153153
154154Using ` Authorization ` has the added benefit over generic custom headers like
155155` X-API-Key ` because it will alert HTTP caching tools to not reuse this response
156- for other users by default.
156+ for other users by default.
157157
158158This is not simply about authorization though, there are lots of other
159159"sensitive" things which should not go into the URL. Email addresses, social
@@ -168,7 +168,7 @@ we're all looking for.
168168## Principle #4 : Limit one-time URLs
169169
170170Logins and file uploads often involve allowing a user to pass in a URL, which
171- will then be downloaded or redirected to.
171+ will then be downloaded or redirected to.
172172
173173``` http
174174POST /products/{productId}/images
@@ -221,7 +221,7 @@ business might not want to expose, or allow outright theft of an entire dataset.
221221
222222A startup tracking street art around the world (think Banksy, Bragga, and
223223smaller artists) built an amazing unique database of user-generated photographs
224- and locations of all sorts of graffiti, sculptures, installations, etc.
224+ and locations of all sorts of graffiti, sculptures, installations, etc.
225225
226226This data was not available anywhere else on the Internet, but their website
227227relied on two API endpoints:
@@ -240,10 +240,11 @@ number of how many active users versus inactive users, leaking a "churn rate"
240240which could be embarrassing in the press of scare off investors.
241241
242242Using the same approach a client can hit ` GET /artworks/1 ` and loop through with `id
243- + 1` to grab a hold of all that data, which helped that company populate their
244- own database, making a new competitor quite easily, and with a slightly better
245- app as they didn't have to spend time or money building the dataset in the first
246- place. This put the original startup out of business.
243+
244+ - 1` to grab a hold of all that data, which helped that company populate their
245+ own database, making a new competitor quite easily, and with a slightly better
246+ app as they didn't have to spend time or money building the dataset in the first
247+ place. This put the original startup out of business.
247248
248249** Design Decision** : There are non-incremental or "hard to guess" system of
249250identifiers instead. Standards like
@@ -282,7 +283,7 @@ thresholds for various user roles:
282283- Paid users: 1,000 requests per hour
283284
284285Communicate these limits clearly in API documentation and return appropriate
285- status codes like ` 429 Too Many Requests ` when limits are exceeded.
286+ status codes like ` 429 Too Many Requests ` when limits are exceeded.
286287
287288Learn more about [ rate limiting] ( /api-design/rate-limiting ) .
288289
@@ -317,7 +318,7 @@ keeping up to date with new editions when they're released.
317318## Tooling
318319
319320Much of this advice and more can be applied to an OpenAPI automatically to help
320- whole teams make good decisions early on in the API design process.
321+ whole teams make good decisions early on in the API design process.
321322
322323- [ Vacuum] ( https://quobix.com/vacuum/ ) via the built in [ OWASP Ruleset] ( https://quobix.com/vacuum/rules/owasp/ ) .
323324- [ Spectral] ( https://github.com/stoplightio/spectral ) with the [ Spectral OWASP Ruleset] ( https://github.com/stoplightio/spectral-owasp-ruleset ) .
@@ -330,10 +331,10 @@ many of the pitfalls outlined here and in the OWASP API Security Top 10 can be a
330331
331332Remember, every design decision is a trade-off. Security measures often add
332333complexity or impact usability. The goal is to strike the right balance,
333- keeping the needs of both API consumers and the business in mind.
334+ keeping the needs of both API consumers and the business in mind.
334335
335336There's no need to go to massive massive and intrusive lengths to secure
336337information that is fine out in the public, but it is important to establish
337- good practices for limiting interactions for more sensitive data.
338+ good practices for limiting interactions for more sensitive data.
338339
339340Maybe this means creating more than one API.
0 commit comments