Forum Discussion

pedinopa_170325's avatar
pedinopa_170325
Icon for Nimbostratus rankNimbostratus
Aug 29, 2017

404 irule with security headers

I am writting an irule to return a ifile (for a 404 error). In addition to returning the ifile (which does work) I want to insert security headers (this isnt working. How can I insert these headers

 

when HTTP_REQUEST { set host [HTTP::host] set path [HTTP::path] switch $path { "/PageNotFound" { HTTP::respond 200 content [ifile get "PageNotFound_html"] } } } when HTTP_RESPONSE {

 

if { [HTTP::status] eq "404" } { HTTP::redirect "https://${host}/PageNotFound?url=${path}" HTTP::header insert "X-Frame-Options" "DENY" HTTP::header insert "X-XSS-Protection" "1; mode=block" HTTP::header insert "X-Content-Type-Options" "'nosniff'" }

 

}

 

1 Reply

  • Hello Pedinopa,

    Try this

    when HTTP_REQUEST { 
    
    set host [HTTP::host] 
    set path [HTTP::path] 
    
        switch $path { 
    
        "/PageNotFound" { 
            HTTP::respond 200 content [ifile get "PageNotFound_html"] "X-Frame-Options" "DENY" "X-XSS-Protection" "1; mode=block" "X-Content-Type-Options" "'nosniff'" "Connection" "Close"
        } 
    
        }
    
    } 
    
    when HTTP_RESPONSE {
    
        if { [HTTP::status] eq "404" } { 
            HTTP::redirect "https://${host}/PageNotFound?url=${path}" 
        }
    
    }
    

    Please give a feedback

    Hope it helps