Skip to content

Commit

Permalink
Add rule use-of-basic-authentication (OpenAPI Spec) (#3370)
Browse files Browse the repository at this point in the history
* Add rule use-of-basic-authentication (OpenAPI)

* Update: Restricted to version 3. Version 2 uses 'securityDefinitions' instead of 'components/securitySchemes'

---------

Co-authored-by: Vasilii Ermilov <inkz@xakep.ru>
  • Loading branch information
aabashkin and inkz authored May 7, 2024
1 parent 28047e0 commit b6d791b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
36 changes: 36 additions & 0 deletions yaml/openapi/security/use-of-basic-authentication.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.1.0
info:
title: Example API
description: Example API
version: 1.0.0

servers:
- url: https://api.example.com/

paths:
/test/{param}:
get:
operationId: test
parameters:
- name: param
in: path
required: true
description: test
schema:
type: string

security:
- basicAuth: []
- apiKeyAuth: []

components:
securitySchemes:
basicAuth:
# ruleid: use-of-basic-authentication
type: http
scheme: basic
apiKeyAuth:
# ok: use-of-basic-authentication
type: apiKey
in: header
name: X-API-Key
41 changes: 41 additions & 0 deletions yaml/openapi/security/use-of-basic-authentication.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
rules:
- id: use-of-basic-authentication
languages: [yaml]
message: >-
Basic authentication is considered weak and should be avoided.
Use a different authentication scheme, such of OAuth2, OpenID Connect, or mTLS.
severity: ERROR
patterns:
- pattern-inside: |
openapi: $VERSION
...
components:
...
securitySchemes:
...
$SCHEME:
...
- metavariable-regex:
metavariable: $VERSION
regex: 3.*
- pattern: |
type: http
...
scheme: basic
metadata:
category: security
subcategory: vuln
technology:
- openapi
likelihood: MEDIUM
impact: HIGH
confidence: HIGH
cwe: 'CWE-287: Improper Authentication'
owasp:
- 'A04:2021 Insecure Design'
- 'A07:2021 Identification and Authentication Failures'
references:
- https://cwe.mitre.org/data/definitions/287.html
- https://owasp.org/Top10/A04_2021-Insecure_Design/
- https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/

0 comments on commit b6d791b

Please sign in to comment.