-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Felipe Avelar <[email protected]>
- Loading branch information
1 parent
dcd5236
commit 0313e28
Showing
18 changed files
with
315 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package generic.openapi | ||
|
||
checkOpenAPI(doc) = version { | ||
object.get(doc, "openapi", "undefined") != "undefined" | ||
version = doc.openapi | ||
regex.match("^3\\.0\\.\\d+$", doc.openapi) | ||
} else = version { | ||
version = "undefined" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "d674aea4-ba8b-454b-bb97-88a772ea33f0", | ||
"queryName": "Security array is empty", | ||
"severity": "HIGH", | ||
"category": "Access Control", | ||
"descriptionText": "Security object need to be defined with a default values and, if needed, specified for particular cases on securityScheme", | ||
"descriptionUrl": "https://swagger.io/specification/#security-requirement-object", | ||
"platform": "OpenAPI" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package Cx | ||
|
||
import data.generic.openapi as openAPILib | ||
|
||
CxPolicy[result] { | ||
doc := input.document[i] | ||
openAPILib.checkOpenAPI(doc) != "undefined" | ||
object.get(doc, "security", "undefined") == "undefined" | ||
|
||
result := { | ||
"documentId": doc.id, | ||
"searchKey": "openapi", | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "A default security schema should be defined", | ||
"keyActualValue": "A default security schema is not defined", | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
doc := input.document[i] | ||
openAPILib.checkOpenAPI(doc) != "undefined" | ||
object.get(doc, "security", "undefined") != "undefined" | ||
|
||
count(doc.security) == 0 | ||
|
||
result := { | ||
"documentId": doc.id, | ||
"searchKey": "security", | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "A default security schema should be defined", | ||
"keyActualValue": "A default security schema is not defined", | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
assets/queries/openAPI/security_empty_array/test/negative1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "Simple API overview", | ||
"version": "1.0.0" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"operationId": "listVersionsv2", | ||
"summary": "List API versions", | ||
"responses": { | ||
"200": { | ||
"description": "200 response", | ||
"content": { | ||
"application/json": { | ||
"examples": { | ||
"foo": { | ||
"value": { | ||
"versions": [ | ||
{ | ||
"status": "CURRENT", | ||
"updated": "2011-01-21T11:33:21Z", | ||
"id": "v2.0", | ||
"links": [ | ||
{ | ||
"href": "http://127.0.0.1:8774/v2/", | ||
"rel": "self" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"security":[ | ||
{ | ||
"exampleSecurity": [] | ||
} | ||
], | ||
"components": { | ||
"exampleSecurity": { | ||
"type": "http", | ||
"scheme": "basic" | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
assets/queries/openAPI/security_empty_array/test/negative2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Simple API overview | ||
version: 1.0.0 | ||
paths: | ||
"/": | ||
get: | ||
operationId: listVersionsv2 | ||
summary: List API versions | ||
responses: | ||
'200': | ||
description: 200 response | ||
content: | ||
application/json: | ||
examples: | ||
foo: | ||
value: | ||
versions: | ||
- status: CURRENT | ||
updated: '2011-01-21T11:33:21Z' | ||
id: v2.0 | ||
links: | ||
- href: http://127.0.0.1:8774/v2/ | ||
rel: self | ||
security: | ||
- exampleSecurity: [] | ||
components: | ||
exampleSecurity: | ||
type: http | ||
scheme: basic |
43 changes: 43 additions & 0 deletions
43
assets/queries/openAPI/security_empty_array/test/positive1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "Simple API overview", | ||
"version": "1.0.0" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"operationId": "listVersionsv2", | ||
"summary": "List API versions", | ||
"responses": { | ||
"200": { | ||
"description": "200 response", | ||
"content": { | ||
"application/json": { | ||
"examples": { | ||
"foo": { | ||
"value": { | ||
"versions": [ | ||
{ | ||
"status": "CURRENT", | ||
"updated": "2011-01-21T11:33:21Z", | ||
"id": "v2.0", | ||
"links": [ | ||
{ | ||
"href": "http://127.0.0.1:8774/v2/", | ||
"rel": "self" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
assets/queries/openAPI/security_empty_array/test/positive2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "Simple API overview", | ||
"version": "1.0.0" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"operationId": "listVersionsv2", | ||
"summary": "List API versions", | ||
"responses": { | ||
"200": { | ||
"description": "200 response", | ||
"content": { | ||
"application/json": { | ||
"examples": { | ||
"foo": { | ||
"value": { | ||
"versions": [ | ||
{ | ||
"status": "CURRENT", | ||
"updated": "2011-01-21T11:33:21Z", | ||
"id": "v2.0", | ||
"links": [ | ||
{ | ||
"href": "http://127.0.0.1:8774/v2/", | ||
"rel": "self" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"security":[] | ||
} |
24 changes: 24 additions & 0 deletions
24
assets/queries/openAPI/security_empty_array/test/positive3.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Simple API overview | ||
version: 1.0.0 | ||
paths: | ||
"/": | ||
get: | ||
operationId: listVersionsv2 | ||
summary: List API versions | ||
responses: | ||
'200': | ||
description: 200 response | ||
content: | ||
application/json: | ||
examples: | ||
foo: | ||
value: | ||
versions: | ||
- status: CURRENT | ||
updated: '2011-01-21T11:33:21Z' | ||
id: v2.0 | ||
links: | ||
- href: http://127.0.0.1:8774/v2/ | ||
rel: self |
25 changes: 25 additions & 0 deletions
25
assets/queries/openAPI/security_empty_array/test/positive4.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Simple API overview | ||
version: 1.0.0 | ||
paths: | ||
"/": | ||
get: | ||
operationId: listVersionsv2 | ||
summary: List API versions | ||
responses: | ||
'200': | ||
description: 200 response | ||
content: | ||
application/json: | ||
examples: | ||
foo: | ||
value: | ||
versions: | ||
- status: CURRENT | ||
updated: '2011-01-21T11:33:21Z' | ||
id: v2.0 | ||
links: | ||
- href: http://127.0.0.1:8774/v2/ | ||
rel: self | ||
security: [] |
26 changes: 26 additions & 0 deletions
26
assets/queries/openAPI/security_empty_array/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"queryName": "Security array is empty", | ||
"severity": "HIGH", | ||
"line": 2, | ||
"filename": "positive1.json" | ||
}, | ||
{ | ||
"queryName": "Security array is empty", | ||
"severity": "HIGH", | ||
"line": 43, | ||
"filename": "positive2.json" | ||
}, | ||
{ | ||
"queryName": "Security array is empty", | ||
"severity": "HIGH", | ||
"line": 1, | ||
"filename": "positive3.yaml" | ||
}, | ||
{ | ||
"queryName": "Security array is empty", | ||
"severity": "HIGH", | ||
"line": 25, | ||
"filename": "positive4.yaml" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.