Skip to content

ipFilter

thiagobustamante edited this page Aug 16, 2017 · 3 revisions

This filter middleware needs to receive an options object containing the following properties.

Property Type Description Required
blacklist string[] A list containing the IPs that should be blocked. false
whitelist string[] A list containing the IPs that should be allowed. false
message string The message to be sent when a source is blockd by this filter. Defaults to IP not allowed. false
statusCode number The HTTP status code to be sent when a source is blockd by this filter. Defaults to 403. false
database DatabaseConfig Provide a database configuration to the filter looks for changes in the whitelist or blacklist configurations. false

You must inform one between blacklist and whiltelist paramenter (even if it is empty). According to the provided parameter, this filter will works as an whitelist or blaclist filter.

DatabaseConfig

Configure a database to be used to store configuration for the filter. Is the configuration changes on the database, the filter will be updated. Support the following properties:

Property Type Description Required
key string The configuration key to be used in database config table. Defaults to ipFilter:whitelist or ipFilter:blacklist false
checkInterval string or number The interval between database checks for changes in the configurations. You can inform the amount of milisencods, or use a human-interval string. Defaults to '30 seconds'. false

Example:

---
name: TestFilteredAPI
version: 1.0.0
path: filtered/
proxy:
  target:
    host: http://httpbin.org
  timeout: 5000
filter:
- middleware:
    name: ipFilter
    options:
      blacklist:
      - 127.0.0.1
      - "::1"
      statusCode: 403
      message: IP Filtered
      database:
        checkInterval: 'one minute'
        key: 'filteredApi:blacklist'

This configuration will filter requests from localhost and from all IPs stored in the database, referenced by the key filteredApi:blacklist.

Clone this wiki locally