Skip to content

Commit 599e5fa

Browse files
authored
fix: Enhance API Gateway structured logging and Lambda permission rule for improved validation (#231)
* fix: Enhance ApiGatewayStructuredLoggingRule and LambdaStarPermissionRule for improved validation - Added stripping of leading/trailing quotes and whitespace in log format for ApiGatewayStructuredLoggingRule. - Improved validation in LambdaStarPermissionRule by ensuring that statements and principals are dictionaries before accessing their properties. * fix: Removed unnecessary conditional check for "Service" key in principal dictionary, directly accessing it to streamline the code. * chore: update project version and dependencies - Bumped version from 0.3.3 to 0.3.4 in pyproject.toml. - Updated cfn-lint dependency from version 1.33.0 to 1.36.0 for improved functionality and compatibility. - Incremented revision in uv.lock to reflect changes in dependency management. * chore: update aws-serverless plugin version to 0.3.4 - Bumped version from 0.3.3 to 0.3.4 in README.md, tflint.md, and example configuration. - Updated version in main.go to reflect the new plugin version.
1 parent a827a1a commit 599e5fa

File tree

8 files changed

+611
-592
lines changed

8 files changed

+611
-592
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ You can enable the Serverless Rules plugin by adding a plugin section in the `.t
4141
```terraform
4242
plugin "aws-serverless" {
4343
enabled = true
44-
version = "0.3.3"
44+
version = "0.3.4"
4545
source = "github.com/awslabs/serverless-rules"
4646
}
4747
```

cfn-lint-serverless/cfn_lint_serverless/rules/api_gateway.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def _check_log_format(self, log_format: str) -> bool:
7474
JSON first.
7575
"""
7676

77+
# Strip any leading/trailing quotes and whitespace that might be in the string
78+
log_format = log_format.strip()
79+
if (log_format.startswith("'") and log_format.endswith("'")) or (log_format.startswith('"') and log_format.endswith('"')):
80+
log_format = log_format[1:-1]
81+
82+
# Replace context variables with a simple value
7783
log_format = self._log_format_pattern.sub("0", log_format)
7884

7985
try:

cfn-lint-serverless/cfn_lint_serverless/rules/lambda_.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,17 @@ def _get_principals(self, properties) -> List[str]:
133133
principals = []
134134

135135
for statement in properties.get("AssumeRolePolicyDocument", {}).get("Statement", []):
136-
if "Service" not in statement.get("Principal", {}):
136+
if not isinstance(statement, dict):
137+
continue
138+
139+
principal = statement.get("Principal", {})
140+
if not isinstance(principal, dict):
141+
continue
142+
143+
if "Service" not in principal:
137144
continue
138145

139-
services = statement.get("Principal", {}).get("Service")
146+
services = principal["Service"]
140147

141148
if isinstance(services, str):
142149
principals.append(services)
@@ -154,7 +161,13 @@ def _get_actions(self, properties) -> List[str]:
154161
actions = []
155162

156163
for policy in properties.get("Policies", []):
164+
if not isinstance(policy, dict):
165+
continue
166+
157167
for statement in policy.get("PolicyDocument", {}).get("Statement", []):
168+
if not isinstance(statement, dict):
169+
continue
170+
158171
action = statement.get("Action")
159172

160173
if isinstance(action, str):

cfn-lint-serverless/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[project]
22
name = "cfn_lint_serverless"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
description = "Serverless rules for cfn-lint"
55
authors = [{name = "Amazon Web Service"}]
66
readme = "README.md"
77
license = "MIT-0"
88
requires-python = ">=3.9.1,<4"
99
dependencies = [
10-
"cfn-lint>=1.33.0"
10+
"cfn-lint>=1.36.0"
1111
]
1212

1313
[dependency-groups]

cfn-lint-serverless/uv.lock

Lines changed: 583 additions & 583 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/tflint.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can enable the Serverless Rules plugin by adding a plugin section in the `.t
1010
```terraform
1111
plugin "aws-serverless" {
1212
enabled = true
13-
version = "0.3.3"
13+
version = "0.3.4"
1414
source = "github.com/awslabs/serverless-rules"
1515
}
1616
```
@@ -76,7 +76,7 @@ Rules in `tflint` can be disabled either through the `--disable-rule` command-li
7676
```terraform
7777
plugin "aws-serverless" {
7878
enabled = true
79-
version = "0.3.3"
79+
version = "0.3.4"
8080
source = "github.com/awslabs/serverless-rules"
8181
}
8282

examples/tflint/.tflint.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ plugin "aws-serverless" {
66
enabled = true
77
# Uncomment those lines if you are using tflint 0.29 or later
88
# source = "github.com/awslabs/serverless-rules"
9-
# version = "0.3.3"
9+
# version = "0.3.4"
1010
}

tflint-ruleset-aws-serverless/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func main() {
1010
plugin.Serve(&plugin.ServeOpts{
1111
RuleSet: &tflint.BuiltinRuleSet{
1212
Name: "aws-serverless",
13-
Version: "0.3.3",
13+
Version: "0.3.4",
1414
Rules: rules.Rules,
1515
},
1616
})

0 commit comments

Comments
 (0)