Fortinet white logo
Fortinet white logo

CLI Reference

waf api-rules

waf api-rules

To restrict API access, you can use this command to configure certain rules involving API key verification, API key carryover, API user grouping, sub-URL setting, and specified actions FortiWeb will take in case of any API call violation.

Syntax

config waf api-rules

edit <api-rules_name>

set verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

set allow-user-group <allow-user-group_name>

set api-key-location {HTTP-parameter | HTTP-header}

set header-field-name <header-field-name_str>

set parameter-name <parameter-name_str>

set rate-limit-period <rate-limit-period_int>

set rate-limit-requests <rate-limit-requests_int>

set rate-limit-user-period <rate-limit-user-period_int>

set rate-limit-user-requests <rate-limit-user-requests_int>

set jwt-token-secret <string>

set jwt-public-key <string>

set jwks-endpoint <string>

set x-ratelimit-headers <enable|disable>

set action {alert | deny_no_log | alert_deny | block-period}

set block-period <block-period_int>

set severity {High | Medium | Low | Info}

set trigger-policy <trigger-policy_str>

set host <host_str>

set host-status {enable | disable}

config attach-HTTP-header

edit <attach-HTTP-header_id>

set HTTP-header-item <HTTP-header-item_str>

next

end

config match-url-prefixes

edit <match-url-prefixes_id>

set frontend-prefix <frontend-prefix_str>

set backend-prefix <backend-prefix_str>

next

end

config sub-url-setting

edit <sub-url-setting_id>

set HTTP-method {get | post | head | options | trace | connect | delete | put | patch | any}

set type {plain | regular}

set url-expression <url-expression_str>

set verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

set api-key-location {HTTP-parameter | HTTP-header}

set header-field-name <header-field-name_str>

set parameter-name <parameter-name_str>

set rate-limit-period <rate-limit-period_int>

set rate-limit-requests <rate-limit-requests_int>

set rate-limit-user-period <rate-limit-user-period_int>

set rate-limit-user-requests <rate-limit-user-requests_int>

set allow-user-group <allow-user-group_name>

set api-key-inherit {enable | disable}

set jwt-token-secret <string>

set jwt-public-key <string>

set jwks-endpoint <string>

next

end

next

end

Variable

Description

Default

<api-rules_name>

Type a unique name for the API gateway rule.

No default

verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

Select the JWT verification method:

  • disable — disable JWT verification.

  • api-key-verification — When a user makes an API request, the API key will be included in HTTP header or parameter, FortiWeb obtains the API key from the request. When this option is enabled, FortiWeb verifies the key to check whether the key belongs to an valid API user.

  • jwks-endpoint — Used when the issuing system signs tokens using an HMAC algorithm (such as HS256 or HS512). FortiWeb validates the incoming JWT by applying the configured shared secret during signature verification.

  • jwt-public-key — Used when tokens are signed using asymmetric algorithms (such as RS256 or ES256). FortiWeb verifies signatures using a user-provided public key.

  • jwt-token-secret — Enables FortiWeb to retrieve signing keys dynamically from an external JWKS (JSON Web Key Set) endpoint. This is commonly used with modern IdPs such as Azure AD, Okta, Ping, or Keycloak.

disable

allow-user-group <allow-user-group_str>

Select a user group created to define which users have the persmission to access the API.

Available only when verification-mode is api-key-verification.

disable

api-key-location {HTTP-parameter | HTTP-header}

Indicate where FortiWeb can find your API key in HTTP request:

  • HTTP-parameter
  • HTTP-header

HTTP-parameter

header-field-name <header-field-name_str>

Enter the header filed name in which FortiWeb can find the API key when api-key-location is HTTP-header.

No default.

parameter-name <parameter-name_str>

Enter the parameter name in which FortiWeb can find the API key when api-key-location is HTTP-parameter.

No default.

rate-limit-period <rate-limit-period_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-requests <rate-limit-requests_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-user-period <rate-limit-user-period_int>

Limit API requests by users.

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

rate-limit-user-requests <rate-limit-user-requests_int>

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

jwt-token-secret <string>

The shared secret used to verify HMAC-signed JWTs. FortiWeb applies this value to validate token integrity.

Available only when the verification-mode is jwt-token-secret.

No default.

jwt-public-key <string>

A PEM-encoded public key used to verify the JWT signature. Appropriate for RS*, ES*, or PS* algorithms.

Available only when the verification-mode is jwt-public-key.

No default.

jwks-endpoint <string>

URL of the IdP’s JWKS endpoint. FortiWeb periodically retrieves keys from this endpoint to validate token signatures.

Available only when the verification-mode is jwks-endpoint.

No default.

x-ratelimit-headers {enable | disable}

Enable to add X-RateLimit-* headers in the response packet if the user exceeds the rate limit. The following information can be displayed to users: the request limit, the remaining requests, and the minimum time to wait before the user is allowed to send the next request.

disable

action {alert | deny_no_log | alert_deny | block-period}

Select which action FortiWeb will take when it detects any API call violation:

  • alert—Accept the connection and generate an alert email and/or log message.
  • alert_deny—Block the request (or reset the connection) and generate an alert and/or log message.
  • deny_no_log—Block the request (or reset the connection).
  • block-period—Block subsequent requests from the client for a number of seconds. Also configure waf api-rules.

alert

block-period <block-period_int>

Enter the number of seconds that you want to block subsequent requests from a client after FortiWeb detects any API call violation. The valid range is 1–10,000 seconds.

Available only if waf api-rules is set to block-period.

600

severity {High | Medium | Low | Info}

When policy violations are recorded in the attack log, each log message contains a Severity Level (severity_level) field. Select which severity level FortiWeb will use when it logs any API call violation:

  • Informative
  • Low
  • Medium
  • High

Low

trigger-policy <trigger-policy_str>

Select the trigger, if any, that FortiWeb will use when it logs and/or sends an alert email about any API call violation. For details, see "Viewing log messages" on page 1.

No default.

host <host_str>

Select the name of a protected host that the Host: field of an HTTP request must be in to match the API gateway rule.

This option is available only if waf api-rules is enable.

No default.

host-status {enable | disable}

Enable to apply this rule only to HTTP requests for specific web hosts. Also configure waf api-rules.

disable

config attach-HTTP-header

<attach-HTTP-header_id>

Enter the sequence number of the HTTP header.

No default.

HTTP-header-item <HTTP-header-item_str>

Enter the HTTP header item.

No default.

config match-url-prefixes

<match-url-prefixes_id>

The sequence number of the match URL prefixes.

No default.

frontend-prefix <frontend-prefix_str>

Enter the Frontend Prefix; the frontend prefix is the URL path in a client call, for example, /fortiweb/, the URL is like this https://172.22.14.244/ fortiweb/example.json?param=value.

No default.

backend-prefix <backend-prefix_str>

Enter the Backend Prefix; the backend prefix is the path which the client request will be replaced with, for example, /api/v1.0/System/Status/.

After the URL rewriting, the URL is like this https://10.200.3.183:90/api/

v1.0/System/Status/example.json?param=value.

No default.

config sub-url-setting

<sub-url-setting_id>

Enter the sequence number of the sub-URL.

No default.

HTTP-method {get | post | head | options | trace | connect | delete | put | patch | any}

Select the HTTP method from the drop down list.

GET

type {plain | regular}

Select whether the url-expression <url-expression_str> field must contain either:

  • plain —The field is a string that the request URL must exactly.
  • regular—The field is a regular expression that defines a set of matching URLs.

plain

url-expression <url-expression_str>

Depending on your selection in type {plain | regular}, enter either:

  • The literal URL, such as /index.php, that the HTTP request must contain in order to match the input rule. The URL must begin with a backslash ( / ).
  • A regular expression, such as ^/*.php, matching all and only the URLs to which the input rule should apply. The pattern does not require a slash ( / ).; however, it must at least match URLs that begin with a slash, such as /index.cfm.

No default.

verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

Select the JWT verification method:

  • disable — disable JWT verification.

  • api-key-verification — When a user makes an API request, the API key will be included in HTTP header or parameter, FortiWeb obtains the API key from the request. When this option is enabled, FortiWeb verifies the key to check whether the key belongs to an valid API user.

  • jwks-endpoint — Used when the issuing system signs tokens using an HMAC algorithm (such as HS256 or HS512). FortiWeb validates the incoming JWT by applying the configured shared secret during signature verification.

  • jwt-public-key — Used when tokens are signed using asymmetric algorithms (such as RS256 or ES256). FortiWeb verifies signatures using a user-provided public key.

  • jwt-token-secret — Enables FortiWeb to retrieve signing keys dynamically from an external JWKS (JSON Web Key Set) endpoint. This is commonly used with modern IdPs such as Azure AD, Okta, Ping, or Keycloak.

disable

api-key-location {HTTP-parameter | HTTP-header}

Indicate where FortiWeb can find your API key in HTTP request:

  • HTTP-parameter
  • HTTP-header

Available only when api-key-verification is verification-mode.

HTTP-parameter

header-field-name <header-field-name_str>

Enter the header filed name in which FortiWeb can find the API key when api-key-location is HTTP-header.

No default.

parameter-name <parameter-name_str>

Enter the parameter name in which FortiWeb can find the API key when api-key-location is HTTP-parameter.

No default.

rate-limit-period <rate-limit-period_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-requests <rate-limit-requests_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-user-period <rate-limit-user-period_int>

Limit API requests by users.

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

rate-limit-user-requests <rate-limit-user-requests_int>

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

allow-user-group <allow-user-group_name>

Select a user group created to define which users have the persmission to access the API.

Available only when api-key-verification is verification-mode.

No default.

api-key-inherit {enable | disable}

When an user makes an API request, the API key will be included in HTTP header or parameter of sub URL, FortiWeb obtains the API key from the request. When this option is enabled, FortiWeb verifies the key to check whether the key belongs to a valid API user.

disable

jwt-token-secret <string>

The shared secret used to verify HMAC-signed JWTs. FortiWeb applies this value to validate token integrity.

Available only when the verification-mode is jwt-token-secret.

No default.

jwt-public-key <string>

A PEM-encoded public key used to verify the JWT signature. Appropriate for RS*, ES*, or PS* algorithms.

Available only when the verification-mode is jwt-public-key.

No default.

jwks-endpoint <string>

URL of the IdP’s JWKS endpoint. FortiWeb periodically retrieves keys from this endpoint to validate token signatures.

Available only when the verification-mode is jwks-endpoint.

No default.

Related topics

waf api-rules

waf api-rules

To restrict API access, you can use this command to configure certain rules involving API key verification, API key carryover, API user grouping, sub-URL setting, and specified actions FortiWeb will take in case of any API call violation.

Syntax

config waf api-rules

edit <api-rules_name>

set verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

set allow-user-group <allow-user-group_name>

set api-key-location {HTTP-parameter | HTTP-header}

set header-field-name <header-field-name_str>

set parameter-name <parameter-name_str>

set rate-limit-period <rate-limit-period_int>

set rate-limit-requests <rate-limit-requests_int>

set rate-limit-user-period <rate-limit-user-period_int>

set rate-limit-user-requests <rate-limit-user-requests_int>

set jwt-token-secret <string>

set jwt-public-key <string>

set jwks-endpoint <string>

set x-ratelimit-headers <enable|disable>

set action {alert | deny_no_log | alert_deny | block-period}

set block-period <block-period_int>

set severity {High | Medium | Low | Info}

set trigger-policy <trigger-policy_str>

set host <host_str>

set host-status {enable | disable}

config attach-HTTP-header

edit <attach-HTTP-header_id>

set HTTP-header-item <HTTP-header-item_str>

next

end

config match-url-prefixes

edit <match-url-prefixes_id>

set frontend-prefix <frontend-prefix_str>

set backend-prefix <backend-prefix_str>

next

end

config sub-url-setting

edit <sub-url-setting_id>

set HTTP-method {get | post | head | options | trace | connect | delete | put | patch | any}

set type {plain | regular}

set url-expression <url-expression_str>

set verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

set api-key-location {HTTP-parameter | HTTP-header}

set header-field-name <header-field-name_str>

set parameter-name <parameter-name_str>

set rate-limit-period <rate-limit-period_int>

set rate-limit-requests <rate-limit-requests_int>

set rate-limit-user-period <rate-limit-user-period_int>

set rate-limit-user-requests <rate-limit-user-requests_int>

set allow-user-group <allow-user-group_name>

set api-key-inherit {enable | disable}

set jwt-token-secret <string>

set jwt-public-key <string>

set jwks-endpoint <string>

next

end

next

end

Variable

Description

Default

<api-rules_name>

Type a unique name for the API gateway rule.

No default

verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

Select the JWT verification method:

  • disable — disable JWT verification.

  • api-key-verification — When a user makes an API request, the API key will be included in HTTP header or parameter, FortiWeb obtains the API key from the request. When this option is enabled, FortiWeb verifies the key to check whether the key belongs to an valid API user.

  • jwks-endpoint — Used when the issuing system signs tokens using an HMAC algorithm (such as HS256 or HS512). FortiWeb validates the incoming JWT by applying the configured shared secret during signature verification.

  • jwt-public-key — Used when tokens are signed using asymmetric algorithms (such as RS256 or ES256). FortiWeb verifies signatures using a user-provided public key.

  • jwt-token-secret — Enables FortiWeb to retrieve signing keys dynamically from an external JWKS (JSON Web Key Set) endpoint. This is commonly used with modern IdPs such as Azure AD, Okta, Ping, or Keycloak.

disable

allow-user-group <allow-user-group_str>

Select a user group created to define which users have the persmission to access the API.

Available only when verification-mode is api-key-verification.

disable

api-key-location {HTTP-parameter | HTTP-header}

Indicate where FortiWeb can find your API key in HTTP request:

  • HTTP-parameter
  • HTTP-header

HTTP-parameter

header-field-name <header-field-name_str>

Enter the header filed name in which FortiWeb can find the API key when api-key-location is HTTP-header.

No default.

parameter-name <parameter-name_str>

Enter the parameter name in which FortiWeb can find the API key when api-key-location is HTTP-parameter.

No default.

rate-limit-period <rate-limit-period_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-requests <rate-limit-requests_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-user-period <rate-limit-user-period_int>

Limit API requests by users.

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

rate-limit-user-requests <rate-limit-user-requests_int>

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

jwt-token-secret <string>

The shared secret used to verify HMAC-signed JWTs. FortiWeb applies this value to validate token integrity.

Available only when the verification-mode is jwt-token-secret.

No default.

jwt-public-key <string>

A PEM-encoded public key used to verify the JWT signature. Appropriate for RS*, ES*, or PS* algorithms.

Available only when the verification-mode is jwt-public-key.

No default.

jwks-endpoint <string>

URL of the IdP’s JWKS endpoint. FortiWeb periodically retrieves keys from this endpoint to validate token signatures.

Available only when the verification-mode is jwks-endpoint.

No default.

x-ratelimit-headers {enable | disable}

Enable to add X-RateLimit-* headers in the response packet if the user exceeds the rate limit. The following information can be displayed to users: the request limit, the remaining requests, and the minimum time to wait before the user is allowed to send the next request.

disable

action {alert | deny_no_log | alert_deny | block-period}

Select which action FortiWeb will take when it detects any API call violation:

  • alert—Accept the connection and generate an alert email and/or log message.
  • alert_deny—Block the request (or reset the connection) and generate an alert and/or log message.
  • deny_no_log—Block the request (or reset the connection).
  • block-period—Block subsequent requests from the client for a number of seconds. Also configure waf api-rules.

alert

block-period <block-period_int>

Enter the number of seconds that you want to block subsequent requests from a client after FortiWeb detects any API call violation. The valid range is 1–10,000 seconds.

Available only if waf api-rules is set to block-period.

600

severity {High | Medium | Low | Info}

When policy violations are recorded in the attack log, each log message contains a Severity Level (severity_level) field. Select which severity level FortiWeb will use when it logs any API call violation:

  • Informative
  • Low
  • Medium
  • High

Low

trigger-policy <trigger-policy_str>

Select the trigger, if any, that FortiWeb will use when it logs and/or sends an alert email about any API call violation. For details, see "Viewing log messages" on page 1.

No default.

host <host_str>

Select the name of a protected host that the Host: field of an HTTP request must be in to match the API gateway rule.

This option is available only if waf api-rules is enable.

No default.

host-status {enable | disable}

Enable to apply this rule only to HTTP requests for specific web hosts. Also configure waf api-rules.

disable

config attach-HTTP-header

<attach-HTTP-header_id>

Enter the sequence number of the HTTP header.

No default.

HTTP-header-item <HTTP-header-item_str>

Enter the HTTP header item.

No default.

config match-url-prefixes

<match-url-prefixes_id>

The sequence number of the match URL prefixes.

No default.

frontend-prefix <frontend-prefix_str>

Enter the Frontend Prefix; the frontend prefix is the URL path in a client call, for example, /fortiweb/, the URL is like this https://172.22.14.244/ fortiweb/example.json?param=value.

No default.

backend-prefix <backend-prefix_str>

Enter the Backend Prefix; the backend prefix is the path which the client request will be replaced with, for example, /api/v1.0/System/Status/.

After the URL rewriting, the URL is like this https://10.200.3.183:90/api/

v1.0/System/Status/example.json?param=value.

No default.

config sub-url-setting

<sub-url-setting_id>

Enter the sequence number of the sub-URL.

No default.

HTTP-method {get | post | head | options | trace | connect | delete | put | patch | any}

Select the HTTP method from the drop down list.

GET

type {plain | regular}

Select whether the url-expression <url-expression_str> field must contain either:

  • plain —The field is a string that the request URL must exactly.
  • regular—The field is a regular expression that defines a set of matching URLs.

plain

url-expression <url-expression_str>

Depending on your selection in type {plain | regular}, enter either:

  • The literal URL, such as /index.php, that the HTTP request must contain in order to match the input rule. The URL must begin with a backslash ( / ).
  • A regular expression, such as ^/*.php, matching all and only the URLs to which the input rule should apply. The pattern does not require a slash ( / ).; however, it must at least match URLs that begin with a slash, such as /index.cfm.

No default.

verification-mode {disable | api-key-verification | jwks-endpoint | jwt-public-key | jwt-token-secret}

Select the JWT verification method:

  • disable — disable JWT verification.

  • api-key-verification — When a user makes an API request, the API key will be included in HTTP header or parameter, FortiWeb obtains the API key from the request. When this option is enabled, FortiWeb verifies the key to check whether the key belongs to an valid API user.

  • jwks-endpoint — Used when the issuing system signs tokens using an HMAC algorithm (such as HS256 or HS512). FortiWeb validates the incoming JWT by applying the configured shared secret during signature verification.

  • jwt-public-key — Used when tokens are signed using asymmetric algorithms (such as RS256 or ES256). FortiWeb verifies signatures using a user-provided public key.

  • jwt-token-secret — Enables FortiWeb to retrieve signing keys dynamically from an external JWKS (JSON Web Key Set) endpoint. This is commonly used with modern IdPs such as Azure AD, Okta, Ping, or Keycloak.

disable

api-key-location {HTTP-parameter | HTTP-header}

Indicate where FortiWeb can find your API key in HTTP request:

  • HTTP-parameter
  • HTTP-header

Available only when api-key-verification is verification-mode.

HTTP-parameter

header-field-name <header-field-name_str>

Enter the header filed name in which FortiWeb can find the API key when api-key-location is HTTP-header.

No default.

parameter-name <parameter-name_str>

Enter the parameter name in which FortiWeb can find the API key when api-key-location is HTTP-parameter.

No default.

rate-limit-period <rate-limit-period_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-requests <rate-limit-requests_int>

Type the maximum number of API call requests allowed in a certain number of seconds.

No default.

rate-limit-user-period <rate-limit-user-period_int>

Limit API requests by users.

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

rate-limit-user-requests <rate-limit-user-requests_int>

Type the maximum number of API call requests allowed per user in a certain number of seconds.

No default.

allow-user-group <allow-user-group_name>

Select a user group created to define which users have the persmission to access the API.

Available only when api-key-verification is verification-mode.

No default.

api-key-inherit {enable | disable}

When an user makes an API request, the API key will be included in HTTP header or parameter of sub URL, FortiWeb obtains the API key from the request. When this option is enabled, FortiWeb verifies the key to check whether the key belongs to a valid API user.

disable

jwt-token-secret <string>

The shared secret used to verify HMAC-signed JWTs. FortiWeb applies this value to validate token integrity.

Available only when the verification-mode is jwt-token-secret.

No default.

jwt-public-key <string>

A PEM-encoded public key used to verify the JWT signature. Appropriate for RS*, ES*, or PS* algorithms.

Available only when the verification-mode is jwt-public-key.

No default.

jwks-endpoint <string>

URL of the IdP’s JWKS endpoint. FortiWeb periodically retrieves keys from this endpoint to validate token signatures.

Available only when the verification-mode is jwks-endpoint.

No default.

Related topics