Cache usage SHOULD be extensively detailed in the description property
to avoid data leaks or the usage of stale data.
This rule should ensure in some way that the api provider
documented extensively the cache usage to avoid data leaks
or usage of stale data.
The no-transform directive can
be used in responses to avoid transforming proxies to
modify (eg. compress) the content.
For now this ruleset tests:
* the presence of following keywords
in the description: max-age, private, no-store, no-cache,
no-transform.
* that one and only one between Expires and Cache-Control is used.
Cache-Control and Expires should not be used in conjunction,
because Cache-Control overrides Expires when max-age is set.
Instead if neither Cache-Control or Expires are set, clients MAY use heuristic cache
like described in RFC7234.
Cache usage SHOULD be extensively detailed in the description property
to avoid data leaks or the usage of stale data.
This rule should ensure in some way that the api provider
documented extensively the cache usage to avoid data leaks
or usage of stale data.
The no-transform directive can
be used in responses to avoid transforming proxies to
modify (eg. compress) the content.
For now this ruleset tests:
* the presence of following keywords
in the description: max-age, private, no-store, no-cache,
no-transform.
* that one and only one between Expires and Cache-Control is used.
Cache-Control and Expires should not be used in conjunction,
because Cache-Control overrides Expires when max-age is set.
Instead if neither Cache-Control or Expires are set, clients MAY use heuristic cache
like described in RFC7234.
Cache usage SHOULD be extensively detailed in the description property
to avoid data leaks or the usage of stale data.
This rule should ensure in some way that the api provider
documented extensively the cache usage to avoid data leaks
or usage of stale data.
The no-transform directive can
be used in responses to avoid transforming proxies to
modify (eg. compress) the content.
For now this ruleset tests:
* the presence of following keywords
in the description: max-age, private, no-store, no-cache,
no-transform.
* that one and only one between Expires and Cache-Control is used.
Cache-Control and Expires should not be used in conjunction,
because Cache-Control overrides Expires when max-age is set.
Instead if neither Cache-Control or Expires are set, clients MAY use heuristic cache
like described in RFC7234.
Paths should be kebab-case (e.g. path-parameter).
See Italian recommendation RAC_REST_NAME_002.
Headers should be Train-Case / HTTP-Header-Case (e.g. X-Header-Name).
See Italian recommendation RAC_REST_NAME_003.
Schema definitions should be CamelCase (pascal case with blank separator char).
This improves readability and avoid confusion between schema names and properties.
Website:
type: string
format: url
Person:
type: object
properties:
website:
$ref: "#/components/schemas/Website"
OAS do not allow using the following HTTP headers in a specification file: Authorization, Content-Type and Accept. You MUST use the associate functionalities provided by OAS, instead.
'HTTP' headers SHOULD NOT start with 'X-' RFC6648.
'HTTP' headers SHOULD NOT start with 'X-' RFC6648.
A GET request MUST NOT accept a requestBody
because this behavior is not interoperable.
Moreover intermediaries such as reverse proxies
are allowed to strip the content from GET requests.
See RFC7231 for further information.
Sending a requestBody in a DELETE request
is not considered interoperable.
Moreover intermediaries such as reverse proxies
might strip the content from DELETE requests.
See RFC7231 for further information.
Responses with the following status codes usually expected to include a content, which might have zero length: 200, 201, 202, 203, 206. Responses with status code 204 and 205 MUST NOT include a content. See RFC7231 for further information.
Responses with the following status codes usually expected to include a content, which might have zero length: 200, 201, 202, 203, 206. Responses with status code 204 and 205 MUST NOT include a content. See RFC7231 for further information.
Use well defined parameter and schema names, deriving them from the national ontologies available at https://w3id.org/italia/onto/
For example, you can model a person using the following names:
{
"en": {
"given_name": "Mario",
"family_name": "Rossi",
"tax_code": "12345678901"
},
"it": {
"nome_proprio": "Mario",
"cognome": "Rossi",
"codice_fiscale": "12345678901"
}
}
Use well defined parameter and schema names, deriving them from the national ontologies available at https://w3id.org/italia/onto/
Avoid using method names in operationIds because it couples
the API design with the implementation.
An operation that edits an entry can be published with different methods, for example either POST, PUT or PATCH, and while evolving the API you could decide to associate an operationId with another method.
You can use for example
openapi: 3.0.1
...
paths:
/entries:
get:
operationId: list_entries
post:
operationId: create_entry
/entries/{id}:
put:
operationId: upsert_entry
patch:
operationId: edit_entry
Schema of type number or integer must specify a format
to express the associated datatype, eg. int32, int64, ...
You can express similar requirements using the minimum and maximum properties.
See recommendation RAC_REST_FORMAT_004.
To improve interoperability, integer and number formats are constrained to a shared subset.
See recommendation RAC_REST_FORMAT_004.
To improve interoperability, integer and number formats are constrained to a shared subset.
See recommendation RAC_REST_FORMAT_004.
Swagger 2 files are not allowed. Use OpenAPI >= 3.0
Ensure examples are valid against their schema.
Suggests using OpenAPI 3.0.x for better compatibility.
OAuth2 endpoints must use https://
The OAuth2 authorization framework defines various grant types, most notably the AuthorizationCode and the Client Credentials.
Some grant types are now considered insecure
and MUST not be used, including implicit and password.
The new OAuth2.1
still in draft, removes them and suggests to
replace the implicit with authorizationCode + PKCE defined in RFC7636.
For further info, see the OAuth2 section of API Security Guidelines.
The PATCH specification explicits that the request body contains a "patch document" describing the changes to be applied to the target resource.
To avoid confusion, this errata
explains that application/json is not an appropriate media-type for PATCH.
A correct example of PATCH using eg. application/json-patch+json media-type
defined in RFC6902.
paths:
/books/{book_id}:
patch:
requestBody:
content:
application/json-patch+json:
schema:
type: array
...
example: [{ "op": "add", "path": "/baz", "value": "qux" }]
The PATCH method requests that a set of changes described in the
requestBody be applied to the target resource.
A PATCH specification without a requestBody
just applies no changes to the target resource.
Since PATCH has impacts on caches, using it on a different target resource may result in non-interoperable behavior.
For example, to modify the resource at /user/123,
you can use the following PATCH request:
``` PATCH /user/123 Content-Type: application/json-patch+json
[{"op": "replace", "path": "enable", "value": true}] ```
or POST request with the semantic implied by the target url:
POST /user/123/enable
Instead, the following request
is expected to modify the /user/123/enable
subresource, and not the /user/123 one.
``` PATCH /user/123/enable ````
A correct example of PATCH using eg. application/json-patch+json media-type
defined in RFC6902.
paths:
/books/{book_id}:
patch:
requestBody:
content:
application/json-patch+json:
schema:
type: array
...
example: [{ "op": "add", "path": "/baz", "value": "qux" }]
The "/status" endpoint must return "application/problem+json" for all 4xx and 5xx error responses (Down state).
The "/status" error response (4xx/5xx) must be a Problem object (RFC7807).
When you design a REST API, you don't usually need to mention terms like
get, delete and so on in your paths, because this information is
conveyed by the HTTP method.
Instead of using
POST /books/1234/delete HTTP/1.1
Host: api.example
You can simply call
DELETE /books/1234 HTTP/1.1
Host: api.example
Similarly you don't need verbs like list or create because
the HTTP Semantics RFC7231 supports this kind of actions natively
with proper methods and status code.
Instead of
``` POST /create/user HTTP/1.1 Host: api.example Content-Type: application/json
{"given_name": "Mario"} ```
You can use ``` POST /create/user HTTP/1.1 Host: api.example Content-Type: application/json
{"given_name": "Mario"} ```
returning a proper response
``` HTTP/1.1 201 Created Location: /users/1234
```
This simplifies securing your API as you know beforehand the kind of action which is going to be performed.
WARN: This rule is under implementation and just provides an hint.
Error management is a key enabler of a resilient API ecosystem. Enforcing a consistent schema for errors between different APIs, enables client to properly implement an error management strategy, with positive impacts for users.
This rule inspects the schema returned by an error response and
verifies whether it contains the main properties defined in RFC7807:
status, title and detail.
An example of a valid payload is
{
"title": "Not Found",
"status": 404,
"detail": "Book does not exist; id: 123"
}
See recommendation RAC_REST_NAME_007.
WARN: This rule is under implementation and just provides an hint.
Error management is a key enabler of a resilient API ecosystem. Enforcing a consistent schema for errors between different APIs, enables client to properly implement an error management strategy, with positive impacts for users.
Errors should return RFC7807 objects. Instead, this schema
seems to use non standard properties such as:
message, msg and code.
An error of the following form
{
"msg": "Book with id: 123 does not exist.",
"code": 6063
}
can be expressed in RFC7807 with
{
"detail": "Book with id: 123 does not exist.",
"type": "https://api.example/v1/errors/6063",
"status": 404,
"title": "Not Found"
}
Returning an URI in type, instead of an opaque code can help
the client in better identifying the error; moreover the URI
though it should not be dereferenced automatically, can return
an actual resource providing guidance in addressing the issue.
See recommendation RAC_REST_NAME_007.
When a client is warned about a temporary server issue with a 503 status code, the server should explicitly communicate how long to wait before issuing further requests using the Retry-After header.
Retry-After is defined in RFC7231.
Ratelimiting an API preserves a service and limits attack scenario see API4:2019 Lack of Resources & Rate Limiting.
APIs should use the following headers on successful and client error responses:
- X-RateLimit-Limit: number of total requests in a give time window
- X-RateLimit-Remaining: remaining requests in the current window
- X-RateLimit-Reset: number of seconds before the window resets
An example set of headers is the following
X-Ratelimit-Limit: 100
X-Ratelimit-Remaining: 40
X-Ratelimit-Reset: 12
A standardization proposal for ratelimit headers is ongoing inside the IETF HTTPAPI Workgroup. See the draft
429 (Too Many Requests) responses must include either the Retry-After header
or a complete set of RateLimit headers (Limit, Remaining, Reset).
If RateLimit headers are provided for a 429 response, all three headers (Limit, Remaining, Reset) must be present and follow the same naming convention (standard or X- prefix). If both Retry-After and Reset are present, they should ideally represent the same time interval.
API Keys are (usually opaque) strings that are passed in headers, cookies or query parameters to access APIs.
Those keys can be eavesdropped, especially when they are stored in cookies or passed as URL parameters.
security:
- ApiKey: []
paths:
/books: {}
/users: {}
securitySchemes:
ApiKey:
type: apiKey
in: cookie
name: X-Api-Key
URL parameters MUST NOT contain credentials such as apikey, password, or secret.
See RAC_GEN_004