Skip to content

Commit

Permalink
enable BotControlRule and SQLiRuleSet
Browse files Browse the repository at this point in the history
  • Loading branch information
mats16 committed Aug 30, 2022
1 parent 0f3abc6 commit c90ee51
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const project = new awscdk.AwsCdkTypeScriptApp({
'@aws-sdk/client-ses',
'@aws-sdk/client-ssm',
'@aws-sdk/client-wafv2',
//'@aws-sdk/client-workmail',
'@aws-sdk/util-utf8-node',
'@databases/pg',
'@types/aws-lambda',
'cdk-bootstrapless-synthesizer@^2.2.2',
Expand Down
1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion src/functions/create-web-acl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WAFV2Client, CreateWebACLCommand, UpdateWebACLCommand, DeleteWebACLCommand, GetWebACLCommand, CreateWebACLCommandInput } from '@aws-sdk/client-wafv2';
import { fromUtf8 } from '@aws-sdk/util-utf8-node';
import { CdkCustomResourceHandler, CdkCustomResourceResponse } from 'aws-lambda';

const client = new WAFV2Client({ region: 'us-east-1' });
Expand Down Expand Up @@ -53,7 +54,32 @@ const parsePhysicalResourceId = (physicalResourceId: string) => {
export const handler: CdkCustomResourceHandler = async (event, _context) => {
const props = event.ResourceProperties as CreateWebACLCommandInput & { Name: string; ServiceToken: string };
console.log(JSON.stringify(props));
props.Rules?.map(rule => rule.Priority = Number(rule.Priority) );
props.Rules?.map(rule => {
rule.Priority = Number(rule.Priority);
rule.Statement?.ManagedRuleGroupStatement?.ScopeDownStatement?.ByteMatchStatement?.TextTransformations?.map(tf => {
tf.Priority = Number(tf.Priority);
});
rule.Statement?.ManagedRuleGroupStatement?.ScopeDownStatement?.NotStatement?.Statement?.ByteMatchStatement?.TextTransformations?.map(tf => {
tf.Priority = Number(tf.Priority);
});
// for Supabase Studio SSR
if (typeof rule.Statement?.ManagedRuleGroupStatement != 'undefined' && rule.Statement?.ManagedRuleGroupStatement?.VendorName == 'AWS' && rule.Statement?.ManagedRuleGroupStatement?.Name == 'AWSManagedRulesBotControlRuleSet') {
rule.Statement.ManagedRuleGroupStatement.ScopeDownStatement = {
NotStatement: {
Statement: {
ByteMatchStatement: {
SearchString: fromUtf8('node-fetch'),
FieldToMatch: {
SingleHeader: { Name: 'user-agent' },
},
TextTransformations: [{ Priority: 0, Type: 'NONE' }],
PositionalConstraint: 'STARTS_WITH',
},
},
},
};
};
});

switch (event.RequestType) {
case 'Create': {
Expand Down
48 changes: 32 additions & 16 deletions src/supabase-cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,38 @@ export class SupabaseCdn extends Construct {
},
OverrideAction: { None: {} },
},
//{
// Name: 'AWS-AWSManagedRulesBotControlRuleSet',
// Priority: 2,
// Statement: {
// ManagedRuleGroupStatement: {
// VendorName: 'AWS',
// Name: 'AWSManagedRulesBotControlRuleSet',
// },
// },
// VisibilityConfig: {
// SampledRequestsEnabled: true,
// CloudWatchMetricsEnabled: true,
// MetricName: 'AWS-AWSManagedRulesBotControlRuleSet',
// },
// OverrideAction: { None: {} },
//},
{
Name: 'AWS-AWSManagedRulesSQLiRuleSet',
Priority: 2,
Statement: {
ManagedRuleGroupStatement: {
VendorName: 'AWS',
Name: 'AWSManagedRulesSQLiRuleSet',
},
},
VisibilityConfig: {
SampledRequestsEnabled: true,
CloudWatchMetricsEnabled: true,
MetricName: 'AWS-AWSManagedRulesSQLiRuleSet',
},
OverrideAction: { None: {} },
},
{
Name: 'AWS-AWSManagedRulesBotControlRuleSet',
Priority: 3,
Statement: {
ManagedRuleGroupStatement: {
VendorName: 'AWS',
Name: 'AWSManagedRulesBotControlRuleSet',
},
},
VisibilityConfig: {
SampledRequestsEnabled: true,
CloudWatchMetricsEnabled: true,
MetricName: 'AWS-AWSManagedRulesBotControlRuleSet',
},
OverrideAction: { None: {} },
},
],
DefaultAction: { Allow: {} },
} as CreateWebACLCommandInput,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c90ee51

Please sign in to comment.