Skip to main content

conditional-logic Scenario 4 — Detect Access Denied and Handle WAF

Written by RTILA X Engineering Team

Intermediate ~6 min
Prerequisites: conditional-logic/1 conditional-logic/2

What You'll Learn

Chain multiple conditions

Real-World Use Case

Implementing complex sign-up logic

LIVE DEMO

WAF Access Denied

Detect the Access Denied message and branch instead of extracting blocked content.

Access Denied

Reference #18.abc123

EXPECTED OUTPUT

WAF Status

{
  "waf_status": {
    "message": "Access Denied — Reference #18.abc123"
  }
}
RTILA X PROJECT JSON

RTILA X Automation Project

detect-and-handle-waf.json
{
  "name": "Detect_And_Handle_WAF",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/conditional-logic/4"
    ]
  },
  "datasets": {
    "page_data": {
      "item_selector": "css=.real-content table.data-table tbody tr",
      "properties": [
        {
          "name": "id",
          "type": "text",
          "selector": "css=td:nth-child(1)"
        },
        {
          "name": "name",
          "type": "text",
          "selector": "css=td:nth-child(2)"
        },
        {
          "name": "status",
          "type": "text",
          "selector": "css=td:nth-child(3)"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "execute_script",
      "params": {
        "script": "return document.body.innerText.includes('Access Denied') ? 'true' : 'false';",
        "output_variable": "access_denied"
      }
    },
    {
      "command": "if",
      "params": {
        "condition": {
          "type": "variable_contains",
          "variable": "access_denied",
          "value": "true"
        },
        "then": [
          {
            "command": "comment",
            "params": {
              "text": "WAF detected, would rotate proxy"
            }
          }
        ],
        "else": [
          {
            "command": "wait_for_selector",
            "params": {
              "selector": "css=.real-content"
            }
          },
          {
            "command": "extract_data",
            "params": {
              "dataset": "page_data"
            }
          }
        ]
      }
    }
  ]
}

A script condition reads the page body text. If the WAF block text is present, the automation logs a comment and skips extraction. If not, it extracts the real content from the page.

Did you complete this scenario?

Ready to run this automation?

Copy the project JSON above, open RTILA X, create a new project, and paste it.

This scenario covers 2 RTILA X commands and is referenced in 1 learning article.

Continue Learning

Was this helpful?