Skip to main content

Keeping tokens safe

Beta

Static Export is in beta. See what Beta means.

A deployment needs a token that can write to your Cloudflare Workers. The site gets one either from a token you create, or by Connect with Cloudflare. This page explains what the plugin does to protect that token, the setup we recommend, and what the plugin cannot protect against.

What this page says about GitHub tokens applies only to the GitHub Pages preview, which is switched off in this version. Without it the panel asks for no GitHub token. A GitHub token saved while the preview was on is still deleted when you turn Static Export off or uninstall the plugin.

Who can use Static Export​

Static Export, including its tokens, is available only to users who can manage the site's options, which in a standard WordPress site means administrators. Every request the panel makes also needs a valid WordPress session.

On a multisite network, a token set in wp-config.php belongs to the whole network, so only a network administrator can deploy with it. Static Export is not supported on networks as a whole; see What is not supported.

What happens to a token you paste into the panel​

  • It is stored in the WordPress database, encrypted. Saving does not send it to GitHub or Cloudflare.
  • It is never shown again: no screen, request, WP-CLI command, log line, error message or export file returns it or any part of it. The panel only ever learns whether a token is connected.
  • The plugin sends it only to api.github.com or api.cloudflare.com. These requests do not pass through WordPress's HTTP hooks, so other plugins that log outgoing requests do not see it. They still respect WP_HTTP_BLOCK_EXTERNAL, WP_ACCESSIBLE_HOSTS and the WordPress proxy settings.
  • It is deleted when you click Disconnect, when you turn Static Export off, and when you uninstall the plugin.

What a sign-in stores​

Connect with Cloudflare stores no token you created. Instead, Cloudflare gives the site two tokens:

  • one that deploys, and works for one hour;
  • a second one that only lets the site get a new first token when the hour is up.

Both are stored exactly like a pasted token: encrypted with the same key and never shown again. They are sent only to Cloudflare, at api.cloudflare.com and dash.cloudflare.com. The site renews the first token by itself when a deployment or Test connection needs it.

The sign-in passes through a page on connect.ohmyetch.com, run by the makers of Oh My Etch, because Cloudflare only sends people back to one fixed address. That page sees a one-time code, which is useless without a key that never leaves your site. It sees no token, and it stores and logs nothing.

The permission is Cloudflare's Workers Admin for the account you chose. It covers every Worker of that account, not only this site's. It does not reach KV, R2, D1, Pages, your API tokens or the account's members. It cannot be limited to one Worker.

Disconnect removes both tokens from the site and asks Cloudflare to end the connection. Turning Static Export off does the same. Uninstalling the plugin deletes the tokens from the site but does not contact Cloudflare, so Oh My Etch can stay listed in your Cloudflare profile under Connected Applications, with no token left that works. Remove it there if you want.

Comparing the three ways to connect Cloudflare​

Connect with CloudflarePasted API tokenToken in wp-config.php
PermissionWorkers Admin on the chosen account: every WorkerWhat you give it; we recommend Workers Scripts: Edit on one accountWhat you give it; we recommend Workers Scripts: Edit on one account
Where it livesThe database, encryptedThe database, encryptedwp-config.php or the server environment
ExpiryRenewed by the site; ends on Disconnect or at CloudflareThe expiry date you set on CloudflareThe expiry date you set on Cloudflare
A copy of the databaseBoth copies hold the same connection; when both deploy, Cloudflare ends it for bothThe copy holds the same token, which keeps working on bothA database copy does not carry it

The sign-in is the easiest to set up. A pasted token can be limited more narrowly. A token in wp-config.php is the most locked-down, and when it is defined the panel does not offer the sign-in.

A token defined in wp-config.php never enters the database. Add the lines above the /* That's all, stop editing! */ line:

// GitHub Pages (preview only).
define( 'OME_STATIC_EXPORT_GITHUB_TOKEN', 'github_pat_…' );

// Cloudflare.
define( 'OME_STATIC_EXPORT_CLOUDFLARE_API_TOKEN', '…' );
define( 'OME_STATIC_EXPORT_CLOUDFLARE_ACCOUNT_ID', '0123456789abcdef0123456789abcdef' );

You can also set environment variables with the same names on the server.

The panel then shows that the token is set in wp-config.php (or the server environment) and can only be changed there. WP-CLI deployments use it as well. Keep wp-config.php out of version control and backups that other people can read.

The encryption key​

A pasted token is encrypted with a key that comes from:

  • the OME_STATIC_EXPORT_SECRET_KEY constant, when it is defined, or
  • otherwise the WordPress security keys and salts.

When WordPress keeps its salts in the database instead of wp-config.php, the panel warns:

This site keeps its security keys in the database, so the saved token is weakly protected: define OME_STATIC_EXPORT_SECRET_KEY (at least 32 random characters) in wp-config.php, then enter the token again.

Weakly protected means that anyone who can read the database could decrypt the saved token.

This is typical on WP Studio, whose wp-config.php defines no salts. To remove the warning:

  1. Define a random string of at least 32 characters in wp-config.php:

    define( 'OME_STATIC_EXPORT_SECRET_KEY', 'replace-with-a-long-random-string-of-at-least-32-characters' );
  2. Enter the token again in the panel, or click Connect with Cloudflare again if you signed in. The old one was encrypted with the old key.

Or put the token itself in wp-config.php, as described above.

OME_STATIC_EXPORT_SECRET_KEY must be a constant; an environment variable is not read. A value shorter than 32 characters is never used and never replaced by the salts: the panel then refuses to save a token (This site cannot encrypt the token, so it was not saved.).

Changing the key or the salts makes a saved token unreadable. The panel then shows The saved token cannot be read; enter the token again, or disconnect. A Cloudflare sign-in shows Connection ended instead; connect again.

Use least-privilege tokens with an expiry date​

A token that can do little does little harm if it leaks.

  • GitHub (preview only): a fine-grained token for only the one repository, with Contents: Read and write and Pages: Read and write, and Administration: Read and write only if you want the plugin to switch GitHub Pages on. See Create the token.
  • Cloudflare: a token with only Account → Workers Scripts → Edit, limited to one account. See Create the API token. A sign-in has a wider permission; see What a sign-in stores.
  • Give tokens an expiry date where the host offers one, and replace them before they expire with Replace token.

Disconnecting​

Disconnect in step 1 of the Cloudflare destination (or of GitHub Pages, with the preview on) deletes the saved token from this site, after a confirmation. For a pasted token it does not change anything on the host, and it does not revoke the token there. When you stop using a token, also revoke it on GitHub or delete it in the Cloudflare dashboard.

For a connection made with Connect with Cloudflare, Disconnect also asks Cloudflare to end it. If Cloudflare cannot be reached, the panel says so; remove Oh My Etch under Connected Applications in your Cloudflare profile.

Turning Static Export off deletes the saved tokens of both hosts together with the export, and ends a Cloudflare sign-in the same way Disconnect does.

What the plugin cannot protect against​

A token that the server must send cannot be made unrecoverable on that server. In plain words:

  • Anyone who can read both the site's files and its database, or who can run PHP on the site (including any other plugin), can recover a saved token.
  • When you paste a token, it travels to WordPress in a request. A plugin that logs incoming REST requests could see it at that moment. A token in wp-config.php avoids this.
  • While a deployment runs, the token is in the server's memory. A plugin that records full error backtraces during that request could capture it.
  • For a Cloudflare sign-in, another plugin could change the address Cloudflare sends you back to. The connect.ohmyetch.com page shows that address before you continue, so check it.

Least-privilege tokens with an expiry date keep the damage small if any of this happens.