Using the Allow List middleware with Tyk Classic APIs
Last updated: 4 minutes read.
The allow list is a feature designed to restrict access to only specific API endpoints. It rejects requests to endpoints not specifically “allowed”, returning HTTP 403 Forbidden
. This enhances the security of the API by preventing unauthorized access to endpoints that are not explicitly permitted.
When working with Tyk Classic APIs the middleware is configured in the Tyk Classic API Definition. You can do this via the Tyk Dashboard API or in the API Designer.
If you’re using the newer Tyk OAS APIs, then check out the Tyk OAS page.
Configuring the allow list in the Tyk Classic API Definition
To enable and configure the allow list you must add a new white_list
object to the extended_paths
section of your API definition.
Note
Historically, Tyk followed the out-dated whitelist/blacklist naming convention. We are working to remove this terminology from the product and documentation, however this configuration object currently retains the old name.
The white_list
object has the following configuration:
path
: the endpoint pathmethod
: this should be blankignore_case
: if set totrue
then the path matching will be case insensitivemethod_actions
: a shared object used to configure the mock response middleware
The method_actions
object should be configured as follows, with an entry created for each allowed method on the path:
action
: this should be set tono_action
code
: this should be set to200
headers
: this should be blank
For example:
|
|
In this example the allow list middleware has been configured for HTTP GET
and PUT
requests to the /status/200
endpoint. Requests to any other endpoints will be rejected with HTTP 403 Forbidden
, unless they also have the allow list middleware enabled.
Note that the allow list has been configured to be case sensitive, so calls to GET /Status/200
will also be rejected.
Note also that the endpoint path has not been terminated with $
. Requests to, for example, GET /status/200/foobar
will be allowed as the regular expression pattern match will recognize this as GET /status/200
.
Consult section configuring the Allow List in Tyk Operator for details on how to configure allow lists for endpoints using Tyk Operator.
Configuring the Allow List in the API Designer
You can use the API Designer in the Tyk Dashboard to configure the allow list middleware for your Tyk Classic API by following these steps.
Step 1: Add an endpoint for the path and select the plugin
From the Endpoint Designer, add an endpoint that matches the path for which you want to allow access. Select the Whitelist plugin.
Step 2: Configure the allow list
Once you have selected the middleware for the endpoint, the only additional feature that you need to configure is whether to make the middleware case insensitive by selecting Ignore Case.
Step 3: Save the API
Use the save or create buttons to save the changes and activate the allow list middleware.
Configuring the Allow List in Tyk Operator
Similar to the configuration of a Tyk Classic API Definition you must add a new white_list
object to the extended_paths
section of your API definition. Furthermore, the use_extended_paths
configuration parameter should be set to true
.
Note
Historically, Tyk followed the out-dated whitelist/blacklist naming convention. We are working to remove this terminology from the product and documentation, however this configuration object currently retains the old name.
|
|
In this example the allow list middleware has been configured for HTTP GET
requests to the /get
endpoint. Requests to any other endpoints will be rejected with HTTP 403 Forbidden
, unless they also have the allow list middleware enabled. Note that the allow list has been configured to case insensitive, so calls to GET /Get
will also be accepted. Note also that the endpoint path has not been terminated with $
. Requests to, for example, GET /get/foobar
will be allowed as the regular expression pattern match will recognize this as GET /get
.