Skip to content
Back to skills

Cloudflare R2

ASecurity

> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18 > **Official Docs:** https://developers.cloudflare.com/r2/api/s3/api/

  • 13 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
ai-agentsrustbashnodenodejsawsapisecurity

Works with

  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 2 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add ashish7802/awesome-api-skills --skill cloudflare-r2 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cloudflare R2?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cloudflare R2
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ashish7802-cloudflare-r2/badge)](https://www.skillsdirectory.com/skills/ashish7802-cloudflare-r2)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Cloudflare R2 Storage Skill

> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18  
> **Official Docs:** https://developers.cloudflare.com/r2/api/s3/api/

## Overview
Cloudflare R2 provides S3-compatible object storage with zero egress fees. Applications access R2 either via native Cloudflare Workers bindings (`env.MY_BUCKET`) or via the S3 API endpoint `https://<ACCOUNT_ID>.r2.cloudflarestorage.com`.

## Installation
```bash
npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner
```

## Authentication
Create a scoped R2 API Token (Object Read & Write limited to specific buckets) in the Cloudflare dashboard to obtain `R2_ACCESS_KEY_ID` and `R2_SECRET_ACCESS_KEY`, alongside `R2_ACCOUNT_ID`. Always set `region: "auto"`.

## Core Concepts
- **Presigned URLs**: Native Workers R2 bindings (`env.BUCKET`) **cannot** generate presigned URLs directly. To issue presigned PUT/GET URLs for direct browser uploads, use `@aws-sdk/client-s3` + `@aws-sdk/s3-request-presigner` (with `nodejs_compat` in Workers) or `aws4fetch`.
- **CORS for Browser Uploads**: Direct browser `PUT` requests to presigned URLs fail unless an explicit CORS rule allowing your origin, `PUT`/`GET`, and `Content-Type` is configured on the R2 bucket.
- **Public Access**: Never expose private user buckets via `r2.dev`; use short-lived presigned GET URLs or an authenticated Worker proxy.

## Error Handling & Rate Limits
- Enforce `ContentType` and `ContentLength` / max file size checks when minting presigned PUT URLs.
- Retry transient `503 SlowDown` / `429` responses using SDK retries.

## Security Best Practices
- Scope R2 API tokens to a single bucket and minimum required permissions.
- Keep presigned URL expirations short (e.g., 60–300 seconds for uploads).
- Sanitize and generate server-controlled object keys (UUIDs/prefixes) rather than trusting client filenames.

## AI Pitfalls
- Setting `region: "us-east-1"` instead of `region: "auto"` or omitting the account-specific endpoint URL.
- Trying to call `env.MY_BUCKET.createPresignedUrl()` on a Workers binding (method does not exist).
- Sending a different `Content-Type` header from the browser than the one signed in `PutObjectCommand`, causing `SignatureDoesNotMatch`.

## Production Checklist
- [ ] Endpoint formatted as `https://<ACCOUNT_ID>.r2.cloudflarestorage.com` with `region: "auto"`
- [ ] Bucket-scoped R2 token stored in server env vars only
- [ ] Presigned URLs expire within 5 minutes and validate allowed MIME types
- [ ] Bucket CORS policy restricts origins explicitly (no wildcard `*` for credentialed flows)

## References
- [Cloudflare R2 S3 Compatibility](https://developers.cloudflare.com/r2/api/s3/api/)
- [Cloudflare R2 Presigned URLs](https://developers.cloudflare.com/r2/api/s3/presigned-urls/)

## Related skills
- [`aws-s3`](../aws-s3/SKILL.md) — alternative to
- [`cloudflare-workers`](../cloudflare-workers/SKILL.md) — integrates with
- [`cloudinary`](../cloudinary/SKILL.md) — works well with

Files in this skill

  • SKILL.md2.9 KB
  • examples/quickstart.ts905 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.