Skip to main content
Khidzir_MN
Staff
Staff
Nov 25, 2026 9:58 AM UTC

Block specific User-Agent using FortiADC script

Description


There is a requirement to block a specific User-Agent. FortiADC Scripting feature supports this requirement with a custom HTTP script.

Refer to the documentation at the end of this article for more information on the Scripting feature and the respective configuration.


Scope


FortiADC and FortiADC VM.


Solution


There are 2 options with the respective HTTP Response Code.

Option 1: HTTP Response Code 403 Forbidden.

  • This script will check if the User-Agent matches the listed User-Agent and reply with the 403 HTTP Response Code.


when HTTP_REQUEST {

-- Get User-Agent information
agent = HTTP:header_get_value("User-Agent")

-- Check if User-Agent match value listed below
    if agent:lower():find("ua1", 1, true)
    or agent:lower():find("ua2", 1, true)
    or agent:lower():find("ua3", 1, true) then

t = {}
        t["code"] = 403
        t["content"] = "HTTP/1.1 403 Forbidden\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\n403 Forbidden - Access Denied"

-- If matched response with 403 Forbidden
        HTTP:respond(t)

    end
}


  • Information in the traffic logs:

d14c3e49.png


Option 2: HTTP Response Code 503 Service Unavailable.

  • This script will check if the User-Agent matches the listed User-Agent and reply with the 503 HTTP Response Code.


when HTTP_REQUEST {

-- Get User-Agent information
agent = HTTP:header_get_value("User-Agent")

-- Check if User-Agent match value listed below
    if agent:lower():find("ua1", 1, true)
    or agent:lower():find("ua2", 1, true)
    or agent:lower():find("ua3", 1, true) then

-- If matched response with 503 Server Unavailable
    HTTP:close()

    end
}


  • Information in the traffic logs:

9440bc79.png


Related documents:

    Risk and Resilience in the Age of AI. An OT Thought Leadership Summit for Houston's Critical Infrastructure Leaders. Date: Thursday, December 3, 2026. Time: 8:30 am - 1:30 pm (CT). Location: The Westin Houston, Memorial City | 945 Gessner Road, Houston, TX 77024