---
name: apify-security-basics
description: |-
  Secure Apify API tokens, configure proxy access, and protect Actor data.
  Use when hardening API key management, setting up environment-specific tokens,
  rotating a leaked token, or auditing Apify security configuration.
  Trigger with "apify security", "apify secrets", "secure apify token",
  "apify API key security", "rotate apify token".
allowed-tools: Read, Write, Edit, Grep
version: 1.5.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - scraping
  - automation
  - apify
compatibility: Designed for Claude Code
title: apify-security-basics
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/apify-security-basics
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/implementation.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/apify-security-basics`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/apify-security-basics`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/apify-security-basics) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/apify-security-basics`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/apify-security-basics --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/apify-security-basics --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Apify Security Basics

## Overview

Security best practices for Apify API tokens, Actor data, proxy credentials, and webhook verification. Apify uses personal API tokens (prefixed `apify_api_`) for all authentication. Because a single token grants full account access with no per-token scoping, token hygiene is the whole game.

## Prerequisites

- Apify account with Console access
- Understanding of environment variables
- Access to your deployment platform's secrets management

## Token Architecture

Apify uses a single API token per user account for full API access. There is no scope-based permission system per token, so token security is critical.

| Token Type | Format | Where to Find |
|------------|--------|---------------|
| Personal API token | `apify_api_...` | Console > Settings > Integrations |
| Proxy password | Alphanumeric | Console > Proxy > Connection settings |

## Instructions

Follow the six hardening steps in order. Each has a lean summary below; the full
copy-paste code for every step is in
[references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/implementation.md).

1. **Secure token storage** — keep the token in `.env` (never hardcoded) and add
   `.env`, `.env.*.local`, and `storage/` to `.gitignore`. Validate presence at
   startup so the app fails fast:

   ```typescript
   function requireToken(): string {
     const token = process.env.APIFY_TOKEN;
     if (!token) throw new Error('APIFY_TOKEN is required');
     if (!token.startsWith('apify_api_')) console.warn('unexpected token prefix');
     return token;
   }
   ```

2. **Per-environment token isolation** — separate tokens (ideally separate
   accounts) for dev / staging / prod, injected via each platform's secret store
   (`gh secret set`, `vercel env add`, GCP Secret Manager).
3. **Token rotation** — generate the new token first (old stays valid), push to
   every environment, verify it authenticates, then revoke the old one.
4. **Webhook payload verification** — Apify does not sign webhooks; confirm the
   run ID in the payload actually exists, or gate on a shared URL secret compared
   with `crypto.timingSafeEqual`.
5. **Actor data security** — redact sensitive fields before `pushData`; keep
   datasets named and private (no public sharing).
6. **Proxy security** — never log `proxyConfig.newUrl()` (it embeds the proxy
   password); log the proxy group only.

See [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/implementation.md) for the complete
code of every step, and [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/examples.md) for
end-to-end scenarios.

## Output

Applying this skill produces a hardened project state:

- A `.gitignore` that excludes `.env*` and `storage/`, with no token in the tree.
- A startup token validator that throws on a missing/malformed `APIFY_TOKEN`.
- Environment-specific tokens wired into each platform's secret store.
- A documented rotation procedure and a completed **Security Checklist** (below).
- Webhook handlers that reject unverified runs and pipelines that redact PII
  before storage.

## Security Checklist

- [ ] `APIFY_TOKEN` stored in environment variables (never hardcoded)
- [ ] `.env` and `storage/` in `.gitignore`
- [ ] Separate tokens for dev/staging/prod
- [ ] Token rotation schedule documented
- [ ] Webhook endpoints verify source
- [ ] Proxy URLs never logged
- [ ] Scraped PII redacted before storage
- [ ] Named datasets used for sensitive data (no public sharing)
- [ ] CI/CD secrets configured (not in repo)

## Leaked Token Response

If a token is exposed:

1. **Immediately** regenerate token in Console > Settings > Integrations
2. Check recent Actor runs for unauthorized usage
3. Review billing for unexpected charges
4. Rotate proxy password if exposed
5. Audit git history: `git log --all -p -- '*.env' '*.json' | grep apify_api_`

## Error Handling

| Issue | Detection | Mitigation |
|-------|-----------|------------|
| Token in git history | `git log -p \| grep apify_api_` | Rotate token, use BFG to clean |
| Unauthorized runs | Unexpected runs in Console | Rotate token immediately |
| Proxy password exposed | Credentials in logs | Regenerate proxy password |
| Data breach in dataset | PII in public dataset | Delete dataset, sanitize pipeline |

## Examples

Quick starting point — bootstrap a new project's secrets safely:

```bash
cat >> .gitignore <<'EOF'
.env
.env.*.local
storage/
EOF
echo 'APIFY_TOKEN=apify_api_dev_token' > .env
git status --short   # .env must NOT appear
```

Four full worked scenarios — secure bootstrap, cross-environment rotation,
webhook-verify-then-sanitize, and a git-history leak audit — are in
[references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/examples.md).

## Resources

- [Apify Account Security](https://docs.apify.com/platform/collaboration)
- [API Authentication](https://docs.apify.com/api/v2/getting-started)
- [Proxy Connection Settings](https://docs.apify.com/platform/proxy)
- [Full implementation reference](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/implementation.md)
- [Worked examples](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-security-basics/references/examples.md)

## Next Steps

For production deployment hardening beyond secrets — health checks, rate limits,
and monitoring — see the `apify-prod-checklist` skill in this pack.
