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): Fix CKV_OpenAPI_20 #5302

Merged
merged 2 commits into from
Jul 9, 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
10 changes: 10 additions & 0 deletions checkov/openapi/checks/resource/generic/ClearTextAPIKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def __init__(self) -> None:
block_type=BlockType.DOCUMENT)

def scan_entity_conf(self, conf: dict[str, Any], entity_type: str) -> tuple[CheckResult, dict[str, Any]]: # type:ignore[override] # return type is different than the base class
schemes = conf.get("schemes")
if schemes and isinstance(schemes, list):
if "http" not in schemes and "wp" not in schemes:
return CheckResult.PASSED, conf

servers = conf.get("servers")
if servers and isinstance(servers, list):
if not any(server['url'].startswith('http://') for server in servers):
return CheckResult.PASSED, conf

components = conf.get("components")
security_def = conf.get("securityDefinitions")
if components and isinstance(components, dict):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"swagger": "2.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"schemes": [
"https",
"http"
],
"paths": {
"/pets": {
"post": {
"description": "Creates a new pet in the store",
"responses": {
"200": {
"description": "200 response"
}
},
"operationId": "addPet",
"security": [
{
"apiKey1": [],
"apiKey3": []
}
]
}
}
},
"securityDefinitions": {
"apiKey1": {
"type": "apiKey",
"name": "X-API-Key",
"in": "header"
},
"apiKey3": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
swagger: "2.0"
info:
title: Simple API overview
version: 1.0.0
schemes:
- https
- http
paths:
/pets:
post:
description: Creates a new pet in the store
responses:
"200":
description: 200 response
operationId: addPet
security:
- apiKey1: []
apiKey3: []
securityDefinitions:
apiKey1:
type: apiKey
name: X-API-Key
in: header
apiKey3:
type: apiKey
name: X-API-Key
in: query
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"servers": [
{
"url": "https://localhost:8000",
"description": "Local server"
},
{
"url": "http://example.com",
"description": "Example"
}
],
"paths": {
"/pets": {
"post": {
"description": "Creates a new pet in the store",
"responses": {
"200": {
"description": "200 response"
}
},
"operationId": "addPet",
"security": [
{
"apiKey1": [],
"apiKey2": [],
"apiKey3": []
}
]
}
}
},
"components": {
"securitySchemes": {
"apiKey1": {
"type": "apiKey",
"name": "X-API-Key",
"in": "header"
},
"apiKey2": {
"type": "apiKey",
"name": "X-API-Key",
"in": "cookie"
},
"apiKey3": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
servers:
- url: https://localhost:8000
description: Local server
- url: http://example.com
description: example
paths:
/pets:
post:
description: Creates a new pet in the store
responses:
'200':
description: 200 response
operationId: addPet
security:
- apiKey1: []
apiKey2: []
apiKey3: []
components:
securitySchemes:
apiKey1:
type: apiKey
name: X-API-Key
in: header
apiKey2:
type: apiKey
name: X-API-Key
in: cookie
apiKey3:
type: apiKey
name: X-API-Key
in: query
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"swagger": "2.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"schemes": [
"https"
],
"paths": {
"/pets": {
"post": {
"description": "Creates a new pet in the store",
"responses": {
"200": {
"description": "200 response"
}
},
"operationId": "addPet",
"security": [
{
"apiKey1": [],
"apiKey3": []
}
]
}
}
},
"securityDefinitions": {
"apiKey1": {
"type": "apiKey",
"name": "X-API-Key",
"in": "header"
},
"apiKey3": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
swagger: "2.0"
info:
title: Simple API overview
version: 1.0.0
schemes:
- https
paths:
/pets:
post:
description: Creates a new pet in the store
responses:
"200":
description: 200 response
operationId: addPet
security:
- apiKey1: []
apiKey3: []
securityDefinitions:
apiKey1:
type: apiKey
name: X-API-Key
in: header
apiKey3:
type: apiKey
name: X-API-Key
in: query
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"servers": [
{
"url": "https://localhost:8000",
"description": "Local server"
}
],
"paths": {
"/pets": {
"post": {
"description": "Creates a new pet in the store",
"responses": {
"200": {
"description": "200 response"
}
},
"operationId": "addPet",
"security": [
{
"apiKey1": [],
"apiKey2": [],
"apiKey3": []
}
]
}
}
},
"components": {
"securitySchemes": {
"apiKey1": {
"type": "apiKey",
"name": "X-API-Key",
"in": "header"
},
"apiKey2": {
"type": "apiKey",
"name": "X-API-Key",
"in": "cookie"
},
"apiKey3": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
servers:
- url: https://localhost:8000
description: Local server
paths:
/pets:
post:
description: Creates a new pet in the store
responses:
'200':
description: 200 response
operationId: addPet
security:
- apiKey1: []
apiKey2: []
apiKey3: []
components:
securitySchemes:
apiKey1:
type: apiKey
name: X-API-Key
in: header
apiKey2:
type: apiKey
name: X-API-Key
in: cookie
apiKey3:
type: apiKey
name: X-API-Key
in: query
8 changes: 8 additions & 0 deletions tests/openapi/checks/resource/generic/test_ClearTextAPIKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ def test_summary(self):
"/pass.json",
"/pass2.yaml",
"/pass2.json",
"/pass3.yaml",
"/pass3.json",
"/pass4.yaml",
"/pass4.json",
}
failing_resources = {
"/fail.yaml",
"/fail.json",
"/fail2.yaml",
"/fail2.json",
"/fail3.yaml",
"/fail3.json",
"/fail4.yaml",
"/fail4.json",
}

passed_check_resources = {c.file_path for c in report.passed_checks}
Expand Down