Mastodon

CORS Rules

A bucket with no CORS rules works from any website, and every request
still needs a valid key. For most setups that default is all you need,
including a wiki or app that uploads straight from the browser.

Add rules when you want a second layer: only the websites you name may use
the bucket from a browser, even with a valid key. Tools that send no
website (the AWS CLI, rclone, a backup job, your server) are never refused
by a rule.

Add a rule

Open the bucket, then Manage > Advanced Options. Put your site in
Allowed origins, scheme included (https://wiki.example.ca), pick the
methods it uses, and save. The save shows which websites will still get
through before it applies.

The restrict confirm, naming the one website that will still get through and reminding that a key is still required

For a page that uploads, allow PUT and the headers an SDK sends
(Authorization, Content-Type, x-amz-*), and expose ETag for
multipart uploads.

Or set the same rule over S3 with a key that owns the bucket (its admin key,
or an account key):

{
  "CORSRules": [
    {
      "AllowedOrigins": ["https://wiki.example.ca"],
      "AllowedMethods": ["GET", "PUT"],
      "AllowedHeaders": ["*"],
      "ExposeHeaders": ["ETag"]
    }
  ]
}
aws s3api put-bucket-cors --bucket your-bucket-name --cors-configuration file://cors.json \
  --endpoint-url https://montreal-1.buckets.stormdevelopments.ca --profile stormdevelopments

Profile setup is in Connecting S3 Tooling.

Reference

Fields

Field Meaning
Allowed origins One website per line, scheme included. * means any.
Allowed methods GET, PUT, POST, DELETE, HEAD, or Any.
Allowed headers Request headers the browser may send. * for any.
Expose headers Response headers the page's JavaScript may read.
Max age Seconds a browser may reuse its preflight answer. Blank leaves it to the browser.
Rule name Optional, for you.

Raw JSON in the editor shows the same rules in the put-bucket-cors
shape and edits both ways. A rule set over S3 shows up in the editor
unchanged, and get-bucket-cors reads back what the editor saved.

The Raw JSON pane open beside the form, showing the same rule as JSON

If the rules changed since you opened the editor (another tab, a
put-bucket-cors), the save is refused and the editor reloads the live
rules instead of overwriting them.

Static sites

A site served from the bucket and visited directly needs no rules: the page
and its files share one origin. Its files embedded on another domain (a
font, a video, a JSON file) follow the same rules on the web endpoint.

How Storm enforces them

The browser's preflight is answered *, because it carries no key and so
cannot name a bucket. Storm checks the rules on the real request, which
carries your key, the bucket and the Origin, and refuses a website no rule
names with HTTP 403 and the S3 error code cors_origin_refused. Nothing is
read or written. A saved change takes effect within 30 seconds.

The badge beside the editor shows Enforced, or Stored, not enforced
yet
on an endpoint that does not refuse on rules yet.

A refused request is covered in
Troubleshooting.