Skip to content

Commit

Permalink
feat: add ipv6 support for block list
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOrangePuff committed Nov 16, 2023
1 parent da49299 commit 8a96dde
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
35 changes: 34 additions & 1 deletion packages/graphql-mesh-server/lib/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,23 @@ export interface MeshServiceProps {
*/
secrets?: { [key: string]: ssm.IStringParameter | ssm.IStringListParameter };
/**
* List of IP addresses to block (currently only support IPv4)
* List of IPv4 addresses to block
*/
blockedIps?: string[];
/**
* The waf rule priority.
* Defaults to 2
*/
blockedIpPriority?: number;
/**
* List of IPv6 addresses to block
*/
blockedIpv6s?: string[];
/**
* The waf rule priority.
* Defaults to 3
*/
blockedIpv6Priority?: number;
/**
* List of AWS Managed rules to add to the WAF
*/
Expand Down Expand Up @@ -220,6 +229,13 @@ export class MeshService extends Construct {
description: "List of IPs blocked by WAF",
});

const blockedIpv6List = new CfnIPSet(this, "BlockedIpv6List", {
addresses: props.blockedIpv6s || [],
ipAddressVersion: "IPV6",
scope: "REGIONAL",
description: "List of IPv6s blocked by WAF",
});

const defaultRules: CfnWebACL.RuleProperty[] = [
{
name: "IPBlockList",
Expand All @@ -238,6 +254,23 @@ export class MeshService extends Construct {
block: {},
},
},
{
name: "IPv6BlockList",
priority: 3 || props.blockedIpPriority,
statement: {
ipSetReferenceStatement: {
arn: blockedIpv6List.attrArn,
},
},
visibilityConfig: {
cloudWatchMetricsEnabled: true,
metricName: "IPv6BlockList",
sampledRequestsEnabled: true,
},
action: {
block: {},
},
},
];

if (props.rateLimit) {
Expand Down
11 changes: 10 additions & 1 deletion packages/graphql-mesh-server/lib/graphql-mesh-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,23 @@ export type MeshHostingProps = {
*/
notificationArn?: string;
/**
* List of IP addresses to block (currently only support IPv4)
* List of IPv4 addresses to block
*/
blockedIps?: string[];
/**
* The waf rule priority.
* Defaults to 2
*/
blockedIpPriority?: number;
/**
* List of IPv6 addresses to block
*/
blockedIpv6s?: string[];
/**
* The waf rule priority.
* Defaults to 3
*/
blockedIpv6Priority?: number;
/**
* List of AWS Managed rules to add to the WAF
*/
Expand Down

0 comments on commit 8a96dde

Please sign in to comment.