내용으로 건너뛰기

How to redirect to custom block page for all AWS WAF block actions (including managed rule sets)

0

Hi,

we have an AWS WAF configuration with a mix of custom rules and managed rule sets. We would like to redirect all block actions to one specific error page from our website. Currently we have configured the custom error page only for our own custom rules, like so (using AWS CDK in Java):

private static RuleActionProperty blockAction() {
        return RuleActionProperty.builder()
            .block(BlockActionProperty.builder()
                .customResponse(customErrorPage())
                .build())
            .build();
    }

private static CfnWebACL.CustomResponseProperty customErrorPage() {
        return CfnWebACL.CustomResponseProperty.builder()
            .responseCode(302)
            .responseHeaders(List.of(CfnWebACL.CustomHTTPHeaderProperty.builder()
                .name("Location")
                .value("/our-error-page.html")
                .build()))
            .build();
    }

I know it's possible to do so for managed rule sets as well, by overriding them to count action and having a custom block rule, that listens to the rule specific label. The problem is, that for the managed rule sets we override some of the rules inside to count action. That means, we would have to create a custom rule that listens to all specific labels in the managed rule set, except for those, that we want to omit.

This seems to me like a lot of trouble and a very unreadable code afterwards. Is there no way to simply set a default custom block page for all block actions regardless of origin?

Advice would be much appreciated.

Cheers, Georg

1개 답변
1
수락된 답변
전문가

답변함 2년 전

전문가

검토됨 2년 전

전문가

검토됨 2년 전

  • After reading your second link, I found out, that you can actually set a custom error page for the 403 status code in your CloudFront distribution. That way all blocked actions from WAF show that page. So, problem solved.

    Thanks!

  • Glad that you found what you needed. Thanks for accepting my answer!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.