Skip to content

Commit 590be7b

Browse files
committed
Sync open source content 🐝 (from 1c692d459095a74db0c02c6aa635a5f254df6472)
1 parent d600879 commit 590be7b

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

api-design/security.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "Implement robust security measures in your API to protect sensitiv
88
Creating an API is like opening a door to the outside world. Who is allowed
99
through, what they can carry, and where they're allowed to go is incredibly
1010
important. 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

1313
Many API security problems come down to coding errors or misconfigured
1414
infrastructure, 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

5050
Imagine 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

5353
Similarly, 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
5757
to Insecure Direct Object References (IDOR), a common flaw where attackers can
@@ -67,7 +67,7 @@ Authorization: Bearer {access_token}
6767
```
6868

6969
The 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

7272
Refund logic and payment details can be split onto their own endpoints:
7373

@@ -83,7 +83,7 @@ Authorization: Bearer {admin_access_token}
8383

8484
This allows staff handle refunds, but does not leak sensitive credit card
8585
information 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

8888
Better yet, **the payments collection is not even on the API**, it's something only
8989
viewable 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

9696
Any 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

9999
An API could suddenly become public: either intentionally when infrastructure
100100
teams 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

103103
Even if an API is firewalled off from public traffic, another API or service
104104
could have been hacked giving them access to the protected API.
105105

106106
It'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
110110
information 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
113113
to 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

118118
This 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).
121121
This 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

124124
Comical 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

154154
Using `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

158158
This 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

170170
Logins 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
174174
POST /products/{productId}/images
@@ -221,7 +221,7 @@ business might not want to expose, or allow outright theft of an entire dataset.
221221

222222
A startup tracking street art around the world (think Banksy, Bragga, and
223223
smaller 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

226226
This data was not available anywhere else on the Internet, but their website
227227
relied on two API endpoints:
@@ -240,10 +240,11 @@ number of how many active users versus inactive users, leaking a "churn rate"
240240
which could be embarrassing in the press of scare off investors.
241241

242242
Using 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
249250
identifiers instead. Standards like
@@ -282,7 +283,7 @@ thresholds for various user roles:
282283
- Paid users: 1,000 requests per hour
283284

284285
Communicate 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

287288
Learn 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

319320
Much 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

331332
Remember, every design decision is a trade-off. Security measures often add
332333
complexity 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

335336
There's no need to go to massive massive and intrusive lengths to secure
336337
information 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

339340
Maybe this means creating more than one API.

docs/gram/host-mcp/publish-gram-server-mcp-registry.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,5 @@ Your MCP server can now be discovered and installed by MCP clients.
256256
You have now published your Gram MCP server on the official MCP Registry, making it discoverable to developers worldwide.
257257
To maintain and further improve your MCP server, you can:
258258

259-
- Automate publishing with [GitHub Actions workflows](https://github.com/modelcontextprotocol/registry/blob/main/docs/guides/publishing/github-actions.md)
259+
- Automate publishing with [GitHub Actions workflows](https://github.com/modelcontextprotocol/registry/blob/3d3337942b2be642c0eda6cf201ab3c5b74bb26d/docs/guides/publishing/github-actions.md)
260260
- Refine tool definitions and use [tool variations](/docs/gram/concepts/tool-variations) to help LLMs better understand and invoke them accurately

0 commit comments

Comments
 (0)