# Security Headers Checker (`eichan/security-headers-checker`) Actor

- **URL**: https://apify.com/eichan/security-headers-checker.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 85.7% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.01 / actor start

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

## Security Headers Checker

**Actor slug:** `security-headers-checker`\
**Apify Store categories (declare on listing):** `DEVELOPER_TOOLS`\
**Suggested price:** **$0.002 per result** (one dataset item per run; recommendation only, **not configured**).\
**Audience:** Web developers, site maintainers, QA engineers, and small security teams.

### What it does

Fetches only the **first HTTP response** for **one public HTTP or HTTPS URL** and reports presence/absence and public values of six headers:

- `Strict-Transport-Security` (HTTPS only)
- `Content-Security-Policy`
- `X-Content-Type-Options`
- `X-Frame-Options`
- `Referrer-Policy`
- `Permissions-Policy`

This is a **presence check**, not a full audit of header directives or site security. HTTP responses with any status code, including 3xx/4xx/5xx, are inspected. Redirects are **never followed**; a `Location` is not fetched. A header absent on the response is marked missing, except HSTS on HTTP, which is marked not applicable.

### Tiny example input

```json
{
  "url": "https://example.com/"
}
```

### Example output (illustrative, from the included local test fixture)

```json
{
  "url": "https://example.com/",
  "status_code": 200,
  "is_https": true,
  "headers_present": [
    "strict-transport-security",
    "content-security-policy",
    "x-content-type-options",
    "referrer-policy"
  ],
  "headers_missing": ["x-frame-options", "permissions-policy"],
  "headers_not_applicable": [],
  "header_values": {
    "strict-transport-security": "max-age=31536000",
    "content-security-policy": "default-src 'self'",
    "x-content-type-options": "nosniff",
    "x-frame-options": null,
    "referrer-policy": "strict-origin-when-cross-origin",
    "permissions-policy": null
  },
  "error": null
}
```

The live `example.com` site may return **different** headers. Every run produces exactly one item with these fields. Failure items have `error` as a plain-English string; HTTP-specific fields remain `null` or empty lists when unknown.

### Limits and security

- **Exactly one URL**, maximum 2,048 characters, scheme `http` or `https` only; default port 80 or 443 (explicit public ports are permitted).
- **Only DNS and the specified URL** are contacted. No login, no passwords, no cookies, no following redirects, no body download, no write to the target, no crawling additional endpoints.
- Resolves the hostname once and pins the outbound socket to a resolved public IP. Rejects any DNS resolution containing a non-global/private/loopback address, and rejects embedded URL credentials. Allows only public IP destinations.
- 8-second connection timeout; one attempt; no proxy rotation, retries, or bypass of access controls.
- HTTPS certificate validation is enabled. Certificates that fail verification produce a plain-language error item.
- Headers show **presence, not security correctness**: e.g. `Content-Security-Policy` may exist but still be permissive. Header values are truncated at 1,000 characters.
- No third-party packages or Apify SDK. `requirements.txt` intentionally has no dependencies.

### Run locally

From the Actor folder, provide input through either `ACTOR_INPUT_JSON` or `storage/key_value_stores/default/INPUT.json`, then **execute the script**:

```bash
ACTOR_INPUT_JSON='{"url":"https://example.com/"}' python src/main.py
```

Or create the file `storage/key_value_stores/default/INPUT.json`:

```json
{"url":"https://example.com/"}
```

Then run `python src/main.py`. The local dataset item is stored under `storage/datasets/default/000000001.json` (or an incremented filename). Set `APIFY_LOCAL_STORAGE_DIR` to choose another local storage folder.

On Apify, the Actor reads the default input key-value store and posts one item to its own default dataset using the platform-provided `APIFY_TOKEN`. **No visitor/customer credentials are requested or used**. This token is only for Apify storage I/O, never for a target website. No event billing, publication, or price configuration is included.

### Reproducible verification

```bash
python tests/run_smoke.py
python -m unittest discover -s tests -p 'test_*.py' -v
```

The smoke runner **really executes `python src/main.py`** with valid JSON, runs a local TLS fixture with `example.com` test certificate, checks the created dataset JSON, and writes `verification/script-mode-smoke.txt` and `verification/dataset-item.json`. A test-only `sitecustomize.py` routes the test endpoint to a loopback fixture; it is **not shipped in the Docker image**. No live example.com request is claimed in this offline test.

See `tests/` for all rerunnable test code and fixture certificate. For real production verification, build and run on Apify with the prefilled input; **cloud build and live networking were not tested here**.

# Actor input Schema

## `url` (type: `string`):

A full http:// or https:// URL. Example: https://example.com/

## Actor input object example

```json
{
  "url": "https://example.com/"
}
```

# Actor output Schema

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

Dataset containing the Actor's result items

# 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 = {
    "url": "https://example.com/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/security-headers-checker").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 = { "url": "https://example.com/" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/security-headers-checker").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 '{
  "url": "https://example.com/"
}' |
apify call eichan/security-headers-checker --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/security-headers-checker"
        }
    }
}
```

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/aweXUyJEYJE1jiaZJ/builds/nyQus1Z0P7ljPs3zG/openapi.json
