Skip to content

Commit 4756b7a

Browse files
authored
Prevent infinite loops in keyword building (#3665)
* Prevent infinite loops in keyword building * More fixes
1 parent 00501ed commit 4756b7a

File tree

6 files changed

+68
-21
lines changed

6 files changed

+68
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"op": "test",
4+
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
5+
"value": {
6+
"$ref": "#/definitions/YAxisOptions"
7+
}
8+
},
9+
{
10+
"op": "replace",
11+
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
12+
"value": {
13+
"properties": {
14+
"YAxis": {
15+
"$ref": "#/definitions/SingleYAxisOption"
16+
}
17+
}
18+
}
19+
}
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"op": "test",
4+
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
5+
"value": {
6+
"$ref": "#/definitions/YAxisOptions"
7+
}
8+
},
9+
{
10+
"op": "replace",
11+
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
12+
"value": {
13+
"properties": {
14+
"YAxis": {
15+
"$ref": "#/definitions/SingleYAxisOption"
16+
}
17+
}
18+
}
19+
}
20+
]

src/cfnlint/data/schemas/providers/us_east_1/aws-quicksight-dashboard.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -9314,7 +9314,11 @@
93149314
"additionalProperties": false,
93159315
"properties": {
93169316
"YAxisOptions": {
9317-
"$ref": "#/definitions/YAxisOptions"
9317+
"properties": {
9318+
"YAxis": {
9319+
"$ref": "#/definitions/SingleYAxisOption"
9320+
}
9321+
}
93189322
}
93199323
},
93209324
"type": "object"

src/cfnlint/data/schemas/providers/us_east_1/aws-quicksight-template.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -8932,7 +8932,11 @@
89328932
"additionalProperties": false,
89338933
"properties": {
89348934
"YAxisOptions": {
8935-
"$ref": "#/definitions/YAxisOptions"
8935+
"properties": {
8936+
"YAxis": {
8937+
"$ref": "#/definitions/SingleYAxisOption"
8938+
}
8939+
}
89368940
}
89378941
},
89388942
"type": "object"

src/cfnlint/jsonschema/validators.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -413,5 +413,7 @@ def extend(
413413

414414
StandardValidator = create(
415415
validators=_standard_validators,
416-
function_filter=FunctionFilter(),
416+
function_filter=FunctionFilter(
417+
add_cfn_lint_keyword=False,
418+
),
417419
)

test/integration/test_schema_files.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,21 @@ def validate_basic_schema_details(
112112
except RefResolutionError:
113113
self.fail(f"Can't find prop {prop} for {section} in {filepath}")
114114

115-
def _build_keywords(
116-
self, obj: Any, schema_resolver: RefResolver, refs: list[str] | None = None
117-
):
118-
if refs is None:
119-
refs = []
115+
def _build_keywords(self, obj: Any, schema_resolver: RefResolver, refs: list[str]):
120116
if not isinstance(obj, dict):
121117
yield []
122118
return
123119

120+
if "$ref" in obj:
121+
ref = obj["$ref"]
122+
if ref in refs:
123+
yield []
124+
return
125+
_, resolved_schema = schema_resolver.resolve(ref)
126+
yield from self._build_keywords(
127+
resolved_schema, schema_resolver, refs + [ref]
128+
)
129+
124130
if "type" in obj:
125131
if "object" in ensure_list(obj["type"]):
126132
if "properties" in obj:
@@ -134,25 +140,14 @@ def _build_keywords(
134140
):
135141
yield ["*"] + item
136142

137-
if "$ref" in obj:
138-
ref = obj["$ref"]
139-
if ref in refs:
140-
yield []
141-
return
142-
_, resolved_schema = schema_resolver.resolve(ref)
143-
for item in self._build_keywords(
144-
resolved_schema, schema_resolver, refs + [ref]
145-
):
146-
yield item
147-
148143
yield []
149144

150145
def build_keywords(self, schema_resolver):
151146
self._found_keywords.append(
152147
"/".join(["Resources", schema_resolver.referrer["typeName"], "Properties"])
153148
)
154149
for k, v in schema_resolver.referrer.get("properties").items():
155-
for item in self._build_keywords(v, schema_resolver):
150+
for item in self._build_keywords(v, schema_resolver, []):
156151
self._found_keywords.append(
157152
"/".join(
158153
[
@@ -214,7 +209,9 @@ def test_data_module_specs(self):
214209
self.validate_basic_schema_details(
215210
schema_resolver, f"{dirpath}/{filename}"
216211
)
217-
self.build_keywords(schema_resolver)
212+
213+
if region == "us-east-1":
214+
self.build_keywords(schema_resolver)
218215

219216
def cfn_lint(self, validator, _, keywords, schema):
220217
keywords = ensure_list(keywords)

0 commit comments

Comments
 (0)