Skip to content

Enhance Request Header Transform Rules

Last updated View as MarkdownAgent setup

You can forward verified claims from a JSON Web Token (JWT) to your origin in a header by creating a Request Header Transform Rule.

Verified claims are available to Request Header Transform Rules through the http.request.jwt.claims fields. They are not available to URL Rewrite Rules.

For example, the following expression will extract the user claim from a token processed by the token configuration with TOKEN_CONFIGURATION_ID:

lookup_json_string(http.request.jwt.claims["<TOKEN_CONFIGURATION_ID>"][0], "claim_name")

Refer to Configure JWT validation for more information about creating a token configuration.

Create a Request Header Transform Rule

As an example, create a Request Header Transform Rule to send the x-send-jwt-claim-user request header to the origin:

  1. In the Cloudflare dashboard, go to the Rules overview page.

    Go to Overview ↗
  2. Select Create rule > Request Header Transform Rules.

  3. Enter a rule name and a filter expression, if applicable.

  4. Choose Set dynamic.

  5. Set the header name to x-send-jwt-claim-user.

  6. Set the value to:

    lookup_json_string(http.request.jwt.claims["<TOKEN_CONFIGURATION_ID>"][0], "claim_name")

    <TOKEN_CONFIGURATION_ID> is your token configuration ID found in JWT validation and claim_name is the JWT claim you want to add to the header.

Was this helpful?