Web App Firewalls



A web application firewall (WAF) protects your internet-facing applications from common web exploits that could affect their availability, compromise their security, or consume excessive resources. It works by filtering and monitoring HTTP traffic based on a set of rules.

You can use a WAF to:

  • Block malicious traffic using managed rule groups that are curated by security experts.
  • Create your own custom rules to address specific threats.
  • Implement rate-based rules to prevent your resources from being overloaded by excessive requests.

You can use a WAF with the following Stacktape resources:

Usage

With a web service (ALB)

resources:
  myFirewall:
    type: web-app-firewall
    properties:
      scope: regional
  webService:
    type: web-service
    properties:
      loadBalancing:
        type: application-load-balancer
      useFirewall: myFirewall
      packaging:
        type: stacktape-image-buildpack
        properties:
          entryfilePath: ./src/index.ts
      resources:
        cpu: 0.25
        memory: 512

An example of a firewall configuration used with a web service.

With a web service (API GW + CDN)

resources:
  myFirewall:
    type: web-app-firewall
    properties:
      scope: regional
  webService:
    type: web-service
    properties:
      cdn:
        enabled: true
        useFirewall: myFirewall
      packaging:
        type: stacktape-image-buildpack
        properties:
          entryfilePath: ./src/index.ts
      resources:
        cpu: 0.25
        memory: 512

An example of a firewall configuration used with a web service.

With an application load balancer

resources:
  myFirewall:
    type: web-app-firewall
    properties:
      scope: regional
  applicationLoadBalancer:
    type: application-load-balancer
    properties:
      useFirewall: myFirewall

An example of a firewall configuration used with an application load balancer.

With a user pool

resources:
  myFirewall:
    type: web-app-firewall
    properties:
      scope: regional
  userPool:
    type: user-auth-pool
    properties:
      userVerificationType: email-code
      passwordPolicy:
        minimumLength: 8
      useFirewall: myFirewall

An example of a firewall configuration used with a user pool.

With a Lambda (Lambda URL +CDN)

resources:
  myFirewall:
    type: web-app-firewall
    properties:
      scope: regional
  lambda:
    type: function
    properties:
      packaging:
        type: stacktape-lambda-buildpack
        properties:
          entryfilePath: ./src/index.ts
      url:
        enabled: true
      cdn:
        enabled: true
        useFirewall: myFirewall

An example of a firewall configuration used with a Lambda URL.

Scope

The scope determines whether the WAF is used with regional resources or with a CDN.

cdn for CloudFront-attached resources, regional for ALBs, User Pools, or direct API Gateways.

The scope cannot be changed after the firewall is created. If you need to change it, you must delete the old firewall and create a new one.

Rules

All requests to resources protected by the WAF are evaluated against a set of rules.

If omitted, Stacktape uses AWSManagedRulesCommonRuleSet + AWSManagedRulesKnownBadInputsRuleSet by default.

Default rules

If you don't specify any rules, Stacktape applies a default set of managed rules from AWS that protect against common attacks, including those listed in the OWASP Top 10. These rules protect against vulnerabilities like SQL injection and cross-site scripting (XSS).

Specifically, it uses the following rule groups:

  • Common rule set (AWSManagedRulesCommonRuleSet): Protects against a wide range of common vulnerabilities.
  • Known bad inputs (AWSManagedRulesKnownBadInputsRuleSet): Blocks request patterns that are known to be malicious.

You can find more information about these rule groups in the AWS documentation.

Managed rule groups

Managed rule groups are sets of rules maintained by AWS or third-party vendors. They are regularly updated to protect against the latest threats.

While rule groups managed by AWS are typically free, some third-party vendors may charge for their rule groups.

resources:
  regionalFirewall:
    type: web-app-firewall
    properties:
      scope: regional
      rules:
        - type: managed-rule-group
          properties:
            name: AWSManagedRulesCommonRuleSet
            vendorName: AWS
            priority: 0

An example of a reference to a managed rule group.

ManagedRuleGroupAPI referenceParent:ManagedRuleGroup
vendorNameRequired

Vendor name (e.g., AWS for AWS-managed rules).

Type: string

priorityRequired

Evaluation order. Lower = evaluated first. Must be unique across all rules.

Type: number

nameRequired
No description

Type: string

excludedRules

Rules within this group to skip (by rule name). Useful for disabling false positives.

Type: Array of string

overrideAction

None = apply normally, Count = log matches without blocking (dry-run mode).

Type: string ENUM

Possible values: CountNone

disableMetrics

Disable CloudWatch metrics for this rule.

Type: boolean

sampledRequestsEnabled

Save samples of requests matching this rule for inspection in the WAF console.

Type: boolean

Custom rule groups

You can create your own custom rule groups to use across multiple applications. To use an existing custom rule group, you just need to provide its ARN.

resources:
  regionalFirewall:
    type: web-app-firewall
    properties:
      scope: regional
      rules:
        - type: custom-rule-group
          properties:
            name: CustomRuleGroup
            arn: <<ARN of existing rule group>>
            priority: 0

An example of a reference to a custom rule group.

CustomRuleGroupAPI referenceParent:CustomRuleGroup
arnRequired

ARN of the custom WAF rule group.

Type: string

priorityRequired

Evaluation order. Lower = evaluated first. Must be unique across all rules.

Type: number

nameRequired
No description

Type: string

overrideAction

None = apply normally, Count = log matches without blocking (dry-run mode).

Type: string ENUM

Possible values: CountNone

disableMetrics

Disable CloudWatch metrics for this rule.

Type: boolean

sampledRequestsEnabled

Save samples of requests matching this rule for inspection in the WAF console.

Type: boolean

Rate-based rules

Rate-based rules track the number of requests from each originating IP address and trigger an action if the rate exceeds a specified limit within a five-minute period. This is useful for temporarily blocking IP addresses that are sending excessive requests.

You can aggregate requests based on the client's IP address or a forwarded IP address from a proxy or load balancer.

IP = direct client IP, FORWARDED_IP = IP from a header (e.g., X-Forwarded-For behind a proxy).

resources:
  regionalFirewall:
    type: web-app-firewall
    properties:
      scope: regional
      rules:
        - type: rate-based-rule
          properties:
            name: RateRule
            limit: 100
            aggregateBasedOn: IP
            priority: 0

An example of a rate-based rule.

RateBasedStatementAPI referenceParent:RateBasedStatement
limitRequired

Max requests per IP in a 5-minute window. Range: 100–20,000,000. Exceeding triggers the action.

Type: number

priorityRequired

Evaluation order. Lower = evaluated first. Must be unique across all rules.

Type: number

nameRequired
No description

Type: string

aggregateBasedOn

IP = direct client IP, FORWARDED_IP = IP from a header (e.g., X-Forwarded-For behind a proxy).

Type: string ENUM

Possible values: FORWARDED_IPIP

forwardedIPConfig

Header and fallback settings when using FORWARDED_IP aggregation.

Type: ForwardedIPConfig

actionDefault: Block

What to do when the rate limit is exceeded.

Type: string ENUM

Possible values: AllowBlockCaptchaChallengeCount

  • Block: Return 403 (most common for rate limiting).
  • Count: Log only, don't block (useful for testing thresholds).
  • Captcha/Challenge: Verify the client is human.
disableMetrics

Disable CloudWatch metrics for this rule.

Type: boolean

sampledRequestsEnabled

Save samples of requests matching this rule for inspection in the WAF console.

Type: boolean

Monitoring

You can monitor your firewall and its rules using Amazon CloudWatch and the AWS WAF console. By default, metrics and sampled requests are enabled for the firewall as a whole but disabled for individual rules. You can change this behavior using the metricsEnabled and sampledRequestsEnabled properties.

Stacktape will automatically create links to the AWS WAF console and the CloudWatch metrics dashboard in the Stacktape Console.

For more details, see the AWS documentation on metrics and sampled requests.

Pricing

You are charged for:

  • Firewall (WebACL): $5.00 per month.
  • Rules: $1.00 per rule per month.
  • Requests: $0.60 per million requests.

Additional costs may apply for paid managed rule groups from third-party vendors.

For example, a firewall with the default rules will cost $7.00 per month ($5.00 for the firewall and $2.00 for the two default rule groups), plus $0.60 for every million requests.

To learn more, see the AWS WAF pricing page.

Referenceable parameters

The following parameters can be easily referenced using $ResourceParam directive directive.

To learn more about referencing parameters, refer to referencing parameters.

arn
  • Arn of the web-app-firewall.

  • Usage: $ResourceParam('<<resource-name>>', 'arn')
scope
  • Scope of the web-app-firewall (regional or cdn).

  • Usage: $ResourceParam('<<resource-name>>', 'scope')

API reference

WebAppFirewallAPI reference
scopeRequired

cdn for CloudFront-attached resources, regional for ALBs, User Pools, or direct API Gateways.

Type: string ENUM

Possible values: cdnregional

defaultActionDefault: Allow

What happens when no rule matches a request.

Type: string ENUM

Possible values: AllowBlock

  • Allow (recommended): Allow all traffic, block only what rules catch.
  • Block: Block all traffic, allow only what rules explicitly permit (returns 403).
rules

Firewall rules: managed rule groups (AWS presets), custom rule groups, or rate-based rules.

Type: Array of ManagedRuleGroup or CustomRuleGroup or RateBasedStatement

If omitted, Stacktape uses AWSManagedRulesCommonRuleSet + AWSManagedRulesKnownBadInputsRuleSet by default.

customResponseBodies

Custom response bodies for Block actions. Map of key → content type + body.

Type: CustomResponseBodies

captchaImmunityTimeDefault: 300

Seconds a solved CAPTCHA stays valid before requiring re-verification.

Type: number

challengeImmunityTimeDefault: 300

Seconds a solved challenge stays valid before requiring re-verification.

Type: number

tokenDomains

Domains accepted in WAF tokens. Enables token sharing across multiple protected websites.

Type: Array of string

disableMetrics

Disable CloudWatch metrics for the firewall.

Type: boolean

sampledRequestsEnabled

Save samples of matched requests for inspection in the AWS WAF console.

Type: boolean

ForwardedIPConfigAPI referenceParent:RateBasedStatement
fallbackBehaviorRequired

What to do when the header is missing. MATCH = apply rule action, NO_MATCH = skip.

Type: string ENUM

Possible values: MATCHNO_MATCH

headerNameRequired

HTTP header containing the client IP (e.g., X-Forwarded-For).

Type: string