# CORS & Preflight Auditor (`axelhu/cors-preflight-auditor`) Actor

Audit public endpoints for CORS origin policy, credential behavior, OPTIONS preflight, origin reflection, and Vary: Origin cache safety.

- **URL**: https://apify.com/axelhu/cors-preflight-auditor.md
- **Developed by:** [Axel Hu](https://apify.com/axelhu) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.30 / 1,000 endpoint cors audits

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## CORS & Preflight Auditor

Audit public HTTP(S) API endpoints for the CORS decisions a browser is likely
to make. This is aimed at API teams, security reviewers, and QA pipelines that
need structured evidence for simple Origin requests and OPTIONS preflights
without handing an Actor cookies, credentials, or arbitrary header values.

Each successful URL produces one Dataset row with the observed CORS headers,
simple/preflight decisions, redirect evidence, reflection checks, and risk
codes.

### Minimal input

The smallest raw API input is:

```json
{
  "urls": ["https://example.com/"],
  "testOrigin": "https://app.example.com"
}
```

With raw API input, omitted optional fields use runtime defaults:

- `additionalOrigins=[]`
- `requestedMethod="POST"`
- `requestHeaders=[]`
- `concurrency=4`
- `timeoutSecs=20`
- `maxResponseBytes=131072`

The Apify Console input schema intentionally prefills an additional reflection
probe and common request-header names so an interactive run demonstrates more
checks. Those Console prefills are not raw API defaults.

One run accepts **1-20 unique URLs**. Larger jobs must be split into multiple
runs.

### What it checks

- `Access-Control-Allow-Origin` exact/wildcard/multiple-value behavior;
- exact `Access-Control-Allow-Credentials: true` semantics;
- OPTIONS status and requested method/header-name allowance;
- CORS-safelisted `GET`, `HEAD`, and `POST` method semantics;
- case-sensitive matching for non-safelisted method tokens;
- the special rule that `Access-Control-Allow-Headers: *` does **not**
  authorize `Authorization`;
- dynamic Origin reflection across multiple test origins;
- reflected origins without `Vary: Origin`;
- selected response metadata (`Expose-Headers`, `Max-Age`, `Vary`).

OPTIONS redirects are observed as the original 3xx response and are **not**
followed into a later 2xx. Ordinary GET redirects still use the shared safe
fetch path and revalidate every redirect target.

### Example result

Private fixed-code run `aNdzMyxO9n856XtcY` on build
`6RzlYA04blFn9cfeb` observed this successful PATCH + Authorization policy
(abridged):

```json
{
  "requestedUrl": "https://httpbin.org/anything",
  "status": 200,
  "preflightStatus": 200,
  "requestedMethod": "PATCH",
  "requestHeaders": ["authorization"],
  "allowOrigin": "https://app.example.com",
  "allowCredentials": "true",
  "allowHeaders": "authorization",
  "simpleAllowed": true,
  "credentialedSimpleAllowed": true,
  "requestedMethodAllowed": true,
  "requestedHeadersAllowed": true,
  "preflightAllowed": true,
  "credentialedPreflightAllowed": true,
  "riskLevel": "none"
}
```

This is a cited acceptance sample, not a guarantee that another endpoint will
return the same policy.

### Safety and failure boundaries

- Public HTTP(S) targets only, ports 80/443.
- DNS results are validated before connecting; GET redirect targets are
  revalidated.
- Loopback, private, link-local, reserved, and transition targets are rejected.
- No cookies, login, browser automation, arbitrary request headers, proxies, or
  user-supplied header values.
- Users provide only Origin values, a preflight method, and header **names**;
  the Actor constructs the CORS probe headers itself.
- Request count, response bytes, decompression, deadlines, redirects, and
  concurrency are bounded.
- URL query values are redacted from stored diagnostics.

`additionalOrigins` are placed only in the Origin header; the Actor does not
contact those origin hosts. A failed optional reflection probe does not erase a
completed primary + preflight audit.

If the primary or OPTIONS probe fails a network/security/resource check, the
Actor emits a diagnostic row but does not charge a `cors-audited` event. The
run-start event still applies. If every selected URL fails, the run is marked
FAILED rather than reporting false success.

When an Apify `maxTotalChargeUsd` budget cannot fund all requested successful
audits, the Actor reduces `selectedByBudget` **before** doing network work and
sets `budgetLimited=true` in `SUMMARY`.

### Interpretation

`origin-reflection` means more than one tested Origin was echoed. It is not
automatically a vulnerability: a service may intentionally allow several
origins. Reflection is more concerning when credentials are allowed, and a
reflected response without `Vary: Origin` is flagged separately because
shared caches can mix policy responses.

`Access-Control-Allow-Origin: *` plus credentials is also reported as a
configuration smell; browsers do not treat the wildcard as authorization for a
credentialed read.

### Pricing

The current private PPE configuration, measured before independent rereview, is:

- Actor start: **$0.00025/run**
- `cors-audited`: **$0.00030/successfully audited URL**
- minimum explicit `maxTotalChargeUsd`: **$0.001**

These are Actor event charges. Because a run accepts at most 20 URLs, the
arithmetic for fully successful jobs is:

| Successful URLs | Required full runs | Actor event charges |
| ---: | ---: | ---: |
| 1 | 1 | $0.00055 |
| 20 | 1 | $0.00625 |
| 100 | 5 | $0.03125 |
| 1,000 | 50 | $0.31250 |

The 100- and 1,000-URL rows are executable multi-run arithmetic, **not** claims
that one Actor start can accept those inputs.

Apify platform resource usage is a separate developer-side cost and varies by
runtime/network behavior. Fixed-code private samples on build
`6RzlYA04blFn9cfeb` measured:

- one successful URL: about **$0.00014315** platform usage;
- two successful URLs under a $0.001 budget: about **$0.00013604** total;
- one rejected loopback URL: about **$0.00006418** platform usage.

These are sparse acceptance samples, not P95 claims. At the current 20% Apify
margin, the measured failed-run floor is why the start event is $0.00025 rather
than the earlier $0.00005: an $0.00005 start would leave only $0.00004 before
platform resource cost, below the measured failed-run sample.

Recheck pricing before release if repeated one-URL successful platform usage
reaches $0.00030, failed-run usage reaches $0.00016, or the workload/support
profile changes materially.

### Support

Use the Actor's Apify Issues/support entry for reproducible problems. Include
the Apify run ID, the relevant redacted endpoint shape, and expected versus
observed CORS behavior; do not paste credentials, cookies, tokens, or sensitive
query values.

# Actor input Schema

## `urls` (type: `array`):

Public HTTP(S) endpoints to audit. Only ports 80 and 443 are allowed.

## `testOrigin` (type: `string`):

HTTP(S) Origin header to test. This is a header value only; the Actor does not contact the origin.

## `additionalOrigins` (type: `array`):

Up to two extra HTTP(S) origins used only to detect dynamic Origin reflection.

## `requestedMethod` (type: `string`):

Method placed in Access-Control-Request-Method for the OPTIONS probe.

## `requestHeaders` (type: `array`):

Header names only, never values. Sent as Access-Control-Request-Headers.

## `concurrency` (type: `integer`):

Maximum number of endpoint audits running concurrently.

## `timeoutSecs` (type: `integer`):

Maximum time for each GET or OPTIONS request, including DNS and redirects.

## `maxResponseBytes` (type: `integer`):

Body bytes are not analyzed, but reads remain bounded to protect the Actor.

## Actor input object example

```json
{
  "urls": [
    "https://httpbin.org/anything"
  ],
  "testOrigin": "https://app.example.com",
  "additionalOrigins": [
    "https://cors-probe.invalid"
  ],
  "requestedMethod": "POST",
  "requestHeaders": [
    "content-type",
    "authorization"
  ],
  "concurrency": 4,
  "timeoutSecs": 20,
  "maxResponseBytes": 131072
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "urls": [
        "https://httpbin.org/anything"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("axelhu/cors-preflight-auditor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "urls": ["https://httpbin.org/anything"] }

# Run the Actor and wait for it to finish
run = client.actor("axelhu/cors-preflight-auditor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "urls": [
    "https://httpbin.org/anything"
  ]
}' |
apify call axelhu/cors-preflight-auditor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,axelhu/cors-preflight-auditor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/dyNVkZpKJbexeUJKi/builds/jOXmzZDNuO7mcfk9j/openapi.json
