> 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/posture-rules/cloud-saas-active-directory-posture-rules/cortex-posture-query-based-rules/detection-rules-by-name/aws-lambda-function-url-having-overly-permissive-cross-origin-resource-sharing-permissions.md). Agents can also search and read this documentation through its [MCP server](https://cortex-docs.paloaltonetworks.com/~gitbook/mcp).

# AWS Lambda function URL having overly permissive cross-origin resource sharing permissions

### Synopsis

| Field               | Value                                                                                      |
| ------------------- | ------------------------------------------------------------------------------------------ |
| Rule Type           | Detection                                                                                  |
| Finding Type        | AWS Lambda function URL having overly permissive cross-origin resource sharing permissions |
| Finding ID          | 60000812                                                                                   |
| Generates a Finding | This detection rule also generates a finding                                               |
| Severity            | Medium                                                                                     |
| Category            | CONFIGURATION                                                                              |
| Cloud Providers     | AWS                                                                                        |
| Platform Module     | CSPM                                                                                       |
| Asset Types         | LAMBDA\_FUNCTION                                                                           |
| ATT\&CK Tactic      | TA0001 (TA0001)                                                                            |
| ATT\&CK Technique   | T1190 (T1190)                                                                              |

### Description

AWS Lambda functions with overly permissive CORS configurations expose sensitive data and functionality to unauthorized access. Improperly configured CORS settings, specifically using wildcard characters in 'allowOrigins', enable any origin to invoke the function.

Lambda functions act as crucial components in serverless architectures. Misconfiguration of CORS settings allows malicious actors to send unauthorized requests, potentially leading to data breaches, denial-of-service attacks, or exploitation of the function's logic via cross-site scripting. This undermines the security of your application and its associated data.

The impact of this misconfiguration is significant, potentially resulting in unauthorized data access, application logic manipulation, and service disruption. Restricting CORS configuration to specific origins and HTTP methods ensures that only legitimate clients can interact with the Lambda function, mitigating these risks.

To remediate, configure Lambda function CORS settings to explicitly list allowed origins ('allowOrigins') and HTTP methods ('allowMethods'). Avoid using wildcard characters. Regularly review and update these settings as your application's access needs change. Employ least privilege principles in configuring your Lambda function's access control.

### Remediation

**Manual steps:**

Lambda Function - This issue identifies AWS Lambda functions with overly permissive CORS settings, allowing any origin to access the function. This can expose the function to unwarranted requests and potential cross-site scripting attacks. It's crucial to restrict access to authorized domains and HTTP methods to ensure a secure setup:

1. **Identify Affected Lambda Functions:** Use the AWS Lambda console or the AWS CLI to list your Lambda functions. Review the CORS configuration for each function.
2. **Configure CORS Permissions:**

   **Restrict Allowed Origins:** Specify the exact domains (e.g., '<https://www.example.com>') that are allowed to interact with your Lambda function. Avoid using wildcards ('\*').

   **Define Allowed Methods:** List the HTTP methods (e.g., 'GET', 'POST', 'PUT', 'DELETE') that are permitted for the function. Avoid using wildcards ('\*').
3. **Update Lambda Function Configuration:** Modify the CORS configuration of the affected Lambda functions using the AWS Lambda console or the AWS CLI. Refer to the AWS documentation for detailed instructions on configuring CORS permissions: <https://docs.aws.amazon.com/lambda/latest/dg/API_Cors.html>

**Note:** Carefully review and test the updated CORS configuration before deploying it to production. Incorrectly configured CORS settings can lead to unexpected behavior and security vulnerabilities.

**CLI code:**

Lambda Function - This command updates the CORS configuration of the Lambda function URL, restricting access to specific origins, methods, and headers. Replace placeholders with the desired values:

```bash
aws lambda update-function-url-config --function-name ${entity} --cors "AllowCredentials=false,AllowHeaders=<allowHeaders>,AllowMethods=<allowMethods>,AllowOrigins=<allowOrigins>,ExposeHeaders=<exposeHeaders>,MaxAge=<maxAgeSeconds>" --region ${entity}
```

**Terraform code:**

Lambda Function - This Terraform code will modify existing Lambda functions to restrict their CORS permissions. This will help to mitigate the risk of cross-site scripting attacks and ensure that only authorized domains and methods can interact with the function:

```hcl
resource "aws_lambda_function_url" "test_live" {
  # existing configurations
  function_name      = aws_lambda_function.function_name
  qualifier          = "my_alias"
  authorization_type = "AWS_IAM"

  # modify the CORS configuration to restrict allowed origins and methods
  cors {
    # allow credentials
    allow_credentials = true
    # restrict allowed origins to a specific domain
    allow_origins     = ["https://www.example.com"]
    # restrict allowed methods to GET and POST
    allow_methods     = ["GET", "POST"]
    # allow specific headers
    allow_headers     = ["date", "keep-alive"]
    # expose specific headers
    expose_headers    = ["keep-alive", "date"]
    # set the max age for preflight requests
    max_age           = 86400
  }
}
```


---

# 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/posture-rules/cloud-saas-active-directory-posture-rules/cortex-posture-query-based-rules/detection-rules-by-name/aws-lambda-function-url-having-overly-permissive-cross-origin-resource-sharing-permissions.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.
