Skip to main content
CriticalSecretsOWASP A07:2021CWE-798

How to fix: Cloudflare R2 access key in source

Cloudflare R2 secret access keys, paired with an r2.cloudflarestorage.com S3-compatible endpoint, grant full read/write access to R2 buckets.

Why it matters

An exposed R2 secret access key gives an attacker full S3-compatible API access to your Cloudflare R2 buckets: reading and exfiltrating every stored object, overwriting or deleting bucket contents, and running up egress/storage charges on your Cloudflare account.

Cloudflare R2 secret access keys, paired with an r2.cloudflarestorage.com S3-compatible endpoint, grant full read/write access to R2 buckets.

How to fix it

  1. 1Revoke the token in Cloudflare Dashboard → R2 → Manage R2 API Tokens
  2. 2Create a new token scoped to a single bucket with only the permissions your app needs (Object Read only, or Object Read & Write)
  3. 3Keep R2 credentials server-side only and proxy uploads/downloads through your own API

Code examples

Server-only R2 client (S3-compatible SDK)

TypeScript
// Server-only: never import this in a client component
import { S3Client } from '@aws-sdk/client-s3';

const r2 = new S3Client({
  region: 'auto',
  endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
  credentials: {
    accessKeyId: process.env.R2_ACCESS_KEY_ID!,      // server-only
    secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!, // server-only
  },
});

Scope the token to one bucket (Cloudflare Dashboard)

bash
# When creating an R2 API token:
# 1. Select 'Object Read & Write' (not 'Admin Read & Write')
# 2. Restrict to a specific bucket, not 'Apply to all buckets'
# 3. Set a TTL if the token is only needed temporarily

References

Detected automatically by VulnRadar. The check id is secret-cloudflare-r2-access-key, stable across every scan so you can filter or diff on it.

See every secrets check

Questions

How severe is Cloudflare R2 access key in source?
VulnRadar rates this critical severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id secret-cloudflare-r2-access-key, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Cloudflare R2 access key in source map to?
It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for cloudflare r2 access key in source

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Cloudflare R2 access key in source | VulnRadar