> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/appsec-rules/iac-security/iam/appsec-openapi-8.md).

# API spec includes a 'password' flow in OAuth2 authentication misconfiguration detected in code

## Rule Details

|                        |                        |
| ---------------------- | ---------------------- |
| Cortex AppSec Rule ID  | APPSEC\_OPENAPI\_8     |
| Category - Subcategory | Public Exposure - APIs |
| Provider               | OTHER                  |
| Severity               | HIGH                   |
| Framework              | OpenAPI                |

## Impact

This rule evaluates if 'password' flow is being used in OAuth2 authentication specifically for version 2.0 files. The 'password' flow, also known as the Resource Owner Password Credentials flow, is generally not secure. It involves providing the user's credentials (username and password) directly to the client, which then exchanges these for an access token. This method can expose user credentials to a potentially malicious client, creating a significant security risk. Therefore, it is not recommended to use the 'password' flow in OAuth2 authentication unless it's assumed that the client is highly trustworthy.

## How to Fix

**OpenAPI**

To fix this issue, you need to modify the specification of your OAuth2 authentication to not use 'password' flow. This is because 'password' flow of OAuth2 authentication is less secure compared to other flows like 'authorization\_code', 'implicit', etc.

```yaml
components:
  securitySchemes:
    OAuth2:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: http://api.example.com/auth
          scopes:
            read: Grants read access
            write: Grants write access
        authorizationCode:
          authorizationUrl: http://api.example.com/auth
          tokenUrl: http://api.example.com/token
          scopes:
            admin: Grants access to admin operations
```

The above code is secure because it uses 'implicit' and 'authorizationCode' flows of OAuth2 authentication instead of the 'password' flow. Both 'implicit' and 'authorizationCode' flows are OAuth2’s response types that are more secure than the 'password' flow. 'implicit' flow is recommended for applications whose server side components are not capable of maintaining the confidentiality of the client secret while 'authorizationCode' flow is used when the client is confidential (can keep a secret) and maintains a server-side component.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/appsec-rules/iac-security/iam/appsec-openapi-8.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
