Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(openapi): add security definition type validation into CKV_OPENAPI_9 #5262

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def scan_openapi_conf(self, conf: dict[str, Any], entity_type: str) -> tuple[Che
return CheckResult.FAILED, conf
if not isinstance(auth_definition, dict):
return CheckResult.UNKNOWN, conf
definition_type = auth_definition.get('type', {})
if definition_type != "oauth2":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a failing state for the UTs as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it already exists openapi/checks/resource/v2/example_OperationObjectSecurityScopeUndefined/fail1.json this fix handles false positives.

continue
definition_scopes = auth_definition.get('scopes', {})
if not definition_scopes:
return CheckResult.FAILED, conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pass:
- "pass1.yaml"
- "pass1.json"
- "pass2.yaml"
- "pass2.json"
fail:
- "fail1.json"
- "fail1.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"security": [
{
"some_auth": []
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
},
"securityDefinitions": {
"some_auth": {
"type": "apiKey"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
swagger: "2.0"
info:
title: Simple API Overview
version: 1.0.0
paths:
/:
get:
operationId: listVersionsv2
summary: List API versions
security:
- some_auth: []
responses:
"200":
description: Success
securityDefinitions:
some_auth:
type: apiKey