Skip to content
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
Empty file.
Empty file.
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions ql/src/security/CWE-942/InsecureCorsAllHeaders.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @name Insecure CORS: All Headers Allowed
* @description Flags CORS policies that allow all headers ("*"), which can increase attack surface.
* @kind problem
* @problem.severity error
* @security-severity 4.0
* @precision high
* @id bicep/insecure-cors-all-headers
* @tags security
* bicep
*/

import bicep

from Network::CorsPolicy cors, Containers::ContainerResource resource
where
resource.getCorsPolicy() = cors and
exists(Array headers | headers = cors.getAllowedHeaders() |
exists(StringLiteral header | header = headers.getElements() | header.getValue() = "*")
)
select cors.getAllowedHeaders(),
"CORS policy allows all headers (\"*\"), which can increase attack surface."
17 changes: 17 additions & 0 deletions ql/src/security/CWE-942/InsecureCorsAllMethods.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @name Insecure CORS: All Methods Allowed
* @description Flags CORS policies that allow all HTTP methods ("*") which can expose APIs to abuse.
* @kind problem
* @problem.severity warning
* @id bicep/insecure-cors-all-methods
*/

import bicep

from Network::CorsPolicy cors, Network::Ingress ingress, Resource resource
where
ingress.getCorsPolicy() = cors and
exists(Array methods | methods = cors.getAllowedMethods() |
exists(StringLiteral method | method = methods.getElements() | method.getValue() = "*")
)
select resource, "CORS policy allows all HTTP methods (\"*\"), which can expose APIs to abuse."
20 changes: 20 additions & 0 deletions ql/src/security/CWE-942/InsecureCorsAllowCredentialsWildcard.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @name Insecure CORS: AllowCredentials with Wildcard Origin
* @description Flags CORS policies that allow credentials with a wildcard origin, which is insecure.
* @kind problem
* @problem.severity error
* @id bicep/insecure-cors-allowcredentials-wildcard
*/
import bicep

from
Network::CorsPolicy cors,
Network::Ingress ingress,
Resource resource
where
ingress.getCorsPolicy() = cors and
cors.allowCredentials() = true and
exists(Array origins | origins = cors.getAllowedOrigins() |
exists(StringLiteral origin | origin = origins.getElements() | origin.getValue() = "*" )
)
select resource, "CORS policy allows credentials with a wildcard origin, which is insecure."
21 changes: 21 additions & 0 deletions ql/src/security/CWE-942/InsecureCorsWildcardOrigin.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @name Insecure CORS: Wildcard Origin
* @description Flags CORS policies that allow any origin ("*"), which is insecure for sensitive APIs.
* @kind problem
* @problem.severity error
* @security-severity 4.0
* @precision high
* @id bicep/insecure-cors-wildcard-origin
* @tags security
* bicep
*/

import bicep

from Network::CorsPolicy cors, Network::Ingress ingress, Resource resource
where
ingress.getCorsPolicy() = cors and
exists(Array origins | origins = cors.getAllowedOrigins() |
exists(StringLiteral origin | origin = origins.getElements() | origin.getValue() = "*")
)
select resource, "CORS policy allows any origin (\"*\"), which is insecure for sensitive APIs."
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| app.bicep:42:27:42:33 | Array | CORS policy allows all headers ("*"), which can increase attack surface. |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
security/CWE-942/InsecureCorsAllHeaders.ql
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
security/CWE-942/InsecureCorsAllMethods.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
security/CWE-942/InsecureCorsAllowCredentialsWildcard.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| app.bicep:2:1:27:1 | ContainerResource | CORS policy allows any origin ("*"), which is insecure for sensitive APIs. |
| app.bicep:30:1:55:1 | ContainerResource | CORS policy allows any origin ("*"), which is insecure for sensitive APIs. |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
security/CWE-942/InsecureCorsWildcardOrigin.ql
55 changes: 55 additions & 0 deletions ql/test/queries-tests/security/CWE-942/app.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Secure CORS example: only specific headers allowed
resource secureContainerApp 'Microsoft.App/containerApps@2022-03-01' = {
name: 'secure-container-app'
location: 'eastus'
properties: {
managedEnvironmentId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.App/managedEnvironments/my-env'
configuration: {
ingress: {
external: true
targetPort: 80
corsPolicy: {
allowCredentials: false
allowedOrigins: [ 'https://example.com' ]
allowedHeaders: [ 'Authorization', 'Content-Type' ]
}
}
}
template: {
containers: [
{
name: 'app'
image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
}
]
}
}
}

// Insecure CORS example: all headers allowed (should be flagged)
resource insecureContainerApp 'Microsoft.App/containerApps@2022-03-01' = {
name: 'insecure-container-app'
location: 'eastus'
properties: {
managedEnvironmentId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.App/managedEnvironments/my-env'
configuration: {
ingress: {
external: true
targetPort: 80
corsPolicy: {
allowCredentials: false
allowedOrigins: [ '*' ]
allowedHeaders: [ '*' ]
}
}
}
template: {
containers: [
{
name: 'app'
image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
}
]
}
}
}