Advisory

GHSA-8mq9-5fw2-5rm4

Details, part 2 of 2. The advisory

Details

Reproduction (validated locally)

Environment: Node 22, @aws-sdk/[email protected], @aws-sdk/[email protected], [email protected]. The harness vendors createMediaHandler byte-for-byte from packages/next-tinacms-s3/src/handlers.ts and runs it against a mocked S3Client. The AWS SDK signs the URL identically whether the bucket exists — the resulting URL is the same one a real S3 deployment would hand back to the editor's browser, so it would PUT against a real bucket without further help.

PoC layout under /Users/admin/joplin_research/tinacms-s3-poc/:

package.json            (deps only)
handler-vendored.mjs    (verbatim copy of createMediaHandler, types stripped)
poc.mjs                 (four exhibits exercising the handler)

Handler is configured the way the package's README documents:

const handler = createMediaHandler({
  config: { region: 'us-east-1', credentials: { accessKeyId: '…', secretAccessKey: '…' } },
  bucket: 'editor-media-bucket',
  mediaRoot: 'media',                 // editors are "scoped to media/"
  authorized: async () => true,       // typical wiring: TinaCloud verified user
});

Run:

$ cd /Users/admin/tinacms-s3-poc && node poc.mjs
--- Exhibit A: presigned PUT URL for arbitrary bucket key ---
  HTTP status : 200
  signedUrl   : https://editor-media-bucket.s3.us-east-1.amazonaws.com/index.html?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAFA...
  src         : https://editor-media-bucket.s3.us-east-1.amazonaws.com/index.html
  signed Key  : /index.html
  RESULT      : BYPASS  (signed URL writes outside media/)

--- Exhibit B: cross-tenant overwrite via attacker-chosen key ---
  signed Key  : /tenant-victim/posts/announcement.mdx
  RESULT      : BYPASS  (cross-tenant write primitive granted)

--- Exhibit C: arbitrary-key DELETE via [...media] route ---
  HTTP status : 200
  S3 Bucket   : editor-media-bucket
  S3 Key      : tenant-victim/posts/announcement.mdx
  RESULT      : BYPASS  (arbitrary-key DELETE granted)

--- Exhibit D: attacker-controlled ?expiresIn ---
  X-Amz-Expires: 604800 sec
  RESULT       : BYPASS  (URL valid far longer than the 1h default)

Verification, in detail:

  1. Exhibit A — GET /api/s3/media?key=index.html. mediaRoot=media/ is configured but never consulted on the write path. The handler hands back a SigV4 URL whose path is /index.html. PUT'ing any body to that URL would create the bucket-root object index.html against the operator's IAM credentials. For a deployment that fronts the bucket with CloudFront / S3-website hosting, this is a one-shot site-defacement primitive (and, for any CSP that trusts the bucket, a one-shot stored-XSS primitive against the published site).
  1. Exhibit B — same primitive, attacker-chosen key tenant-victim/posts/announcement.mdx. In the multi-tenant TinaCloud / TinaCMS Cloud deployment shape (one bucket shared across tenants, each tenant assigned a mediaRoot/<tenant>/ prefix), a Tenant A editor receives a presigned PUT URL for any Tenant B key. Cross-tenant content tampering with no further bug needed.
  1. Exhibit C — DELETE /api/s3/media/anything-here-is-ignored/tenant-victim%2Fposts%2Fannouncement.mdx. The handler reads the catch-all as req.query.media = ['anything-here-is-ignored', 'tenant-victim/posts/announcement.mdx'], destructures to objectKey = media[1], dispatches DeleteObjectCommand({ Bucket: 'editor-media-bucket', Key: 'tenant-victim/posts/announcement.mdx' }). The mock confirms the captured command's Key is the attacker-supplied string. Real S3 will honour the same call. (The mock-captured call confirms the *handler's* behaviour; the real S3 call requires only s3:DeleteObject on the bucket, which the package's README instructs operators to grant.)
  1. Exhibit D — ?expiresIn=604800 (7 days, the SigV4 ceiling). The handler accepts it, the resulting X-Amz-Expires=604800. Combined with Exhibit A, an attacker who briefly compromises a CMS session (e.g. via a stolen idle browser session or the dev-server CSRF write described in finding 06) can mint a long-lived offline write primitive — usable for a week with no further interaction with the CMS.

The four exhibits together: cross-mediaRoot write, cross-tenant write, arbitrary-key delete, and long-lived signed-URL minting.

Impact

  • Cross-tenant / cross-mediaRoot write. In any deployment where the bucket holds anything other than this one editor's mediaRoot (multi-tenant TinaCloud, shared corporate bucket, bucket-backed static site), an authorized editor obtains write authority over every key the IAM credential can reach. Concretely: defacement of a static site fronted by the bucket; cross-tenant content tampering; replacement of *.html, *.js, *.json assets that downstream consumers trust. (Exhibits A, B; handlers.ts:67-90.)
  • Stored XSS via uploaded HTML. S3 returns objects with the Content-Type the upload supplies. The presigned PutObjectCommand URL carries no Content-Type constraint — the attacker's PUT chooses it. An editor can therefore write an HTML / SVG / JS payload to the bucket-root, and any CDN or origin that serves bucket objects directly to an authenticated SaaS surface inherits stored XSS in that origin.
  • Arbitrary-key delete (data destruction). Through [...media] the handler treats the second URL segment as a free-form object key. An editor can wipe any object the IAM key can s3:DeleteObject, including non-media artefacts like deployment manifests, backups, or other tenants' files. (Exhibit C; handlers.ts:199-223.)
  • Bucket-policy implications. The README (lines 38-90) tells operators to grant the IAM key s3:PutObject, s3:PutObjectAcl, s3:DeleteObject, and s3:ListBucket on the *whole* bucket. The README implies the application code constrains the editor's actions to mediaRoot. Because the application code does not, every operator who follows the README has — without realising — granted every CMS editor full write/delete on the whole bucket.
  • Long-lived offline write primitive. expiresIn is attacker-controlled and not capped by the handler. A single GET request mints a URL valid for up to 7 days (AWS SigV4 ceiling). An attacker who briefly compromises a CMS session can stash one such URL and continue writing arbitrary objects long after the session is revoked. (Exhibit D.)
  • Same-shape exposure on every other first-party media adapter. next-tinacms-dos (DigitalOcean Spaces, S3-compatible), next-tinacms-azure (Blob Storage), and next-tinacms-cloudinary (Cloudinary) all duplicate the broken pattern. Azure has *no* mediaRoot config at all, so the boundary that next-tinacms-s3 advertises but doesn't enforce isn't even nominally present in next-tinacms-azure.

Sources & licences