Skip to content

How should my cookie-authenticated backend protect generation commands from cross-site requests?

Protect cookie-authenticated generation commands with your application's CSRF controls, such as framework tokens and reviewed origin checks. Keeping the AISwapLab bearer key on the server does not protect a browser session from being induced to call your own spending endpoint from another site.

PROTECT API ACCESS AND RESULTSAISwapLab team · Editorial methodPublished 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Identify cookie-authenticated mutations; Use framework-supported defenses; Test cross-site attempts locally.
Workflow diagram: Identify cookie-authenticated mutations → Use framework-supported defenses → Test cross-site attempts locally. Read the article for evidence and limits.

The browser authenticates your proxy

Your backend may correctly hide the upstream key while still trusting every request that includes the user's cookies. A cross-site request can then target the application's paid command route. This is a defense for your session architecture, not a new AISwapLab authentication method.

What to do next

  1. 01

    Identify cookie-authenticated mutations

    List generation approval, dispatch and project-change routes that accept ambient browser credentials. Ensure read-only GET requests do not create creative work, and keep mutation routes distinct from status and download operations.

  2. 02

    Use framework-supported defenses

    Apply the framework's CSRF mechanism consistently and verify origin handling for your deployment. Use appropriate cookie attributes as supporting controls, understanding their scope rather than treating any single flag as a universal substitute.

  3. 03

    Test cross-site attempts locally

    From a separate test origin, attempt a synthetic command against the application without a valid CSRF token. Assert it is rejected before action creation or dispatch, while legitimate same-site flows continue working.

A concrete example

Illustrative example: an external page posts to your app's create-action route using the browser's existing session. The server rejects the missing CSRF evidence before inserting an approved action, so the hidden upstream key cannot be spent through that request.

Before you call it ready

  • GET routes never create paid work.
  • CSRF checks precede action creation.
  • Legitimate session flows still pass.

When to stop or choose another method

Stop treating server-only bearer storage as the complete browser-side protection for a cookie-authenticated spending proxy.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation