Skip to content

feat(cms): connect a brand's WordPress site with an Application Password and send pages to it as draft posts (#1331) - #1569

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-wordpress-server
Oct 28, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:feature/cms-wordpress-server

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Send to CMS, phase 2 (#1331): WordPress, server part (1 of 3). After Webflow, a brand connects its WordPress site, and pages go to it through the REST API as draft posts.

Connecting. The person gives the site's address, a user, and an Application Password (WordPress 5.6+, Users › Profile › Application Passwords).

  • The address is read as the site: https is added when left out, /wp-admin and /wp-json copied with it are taken off, and a site in a folder keeps its folder. Only https on the standard port is taken, since the password goes in an Authorization header.
  • The server checks the site before anything is kept:
    • /wp-json/ (_fields=name,namespaces,authentication) answers as WordPress (wp/v2). This is asked without the password: the password goes only to a site that answered as WordPress, or that keeps its API from visitors (401, 403), which is asked again signed in. A mistyped domain never gets it.
    • Application Passwords are on.
    • users/me (context=edit) takes the sign-in.
    • The user can edit_posts.
  • Each step says what to fix, in its own words:
    • not WordPress (or Plain permalinks);
    • a redirect (use the address it goes to);
    • the site refused (a firewall);
    • Application Passwords turned off;
    • the user or the password refused;
    • the server dropped the Authorization header;
    • users hidden by a security plugin;
    • the user can't write posts.
    • WordPress refuses a wrong password on every API call. So when only users/me refuses while the signed-in index answers, the header never reached WordPress. The message then says to save Permalinks once, or to pass the header (the .htaccess line), rather than "wrong password".
  • The site's name is read with its HTML entities decoded (WordPress keeps it escaped).
  • The sign-in is kept the way feat(catalog): connect a store with its own sign-in, kept encrypted by the API, with a connector harness and CONNECTORS.md (00282, #1263 part 3) #1501 keeps a store's: sealed by the API (AES-256-GCM under CONNECTOR_CREDENTIALS_KEY) in the new brand_cms_credentials, which only the service role reads.
    • The envelope is bound to cms:<connection id>, so it opens on its own connection only, never as another's or as a store source's.
    • The password is never kept in the clear, logged or answered with.
  • Disconnect revokes the Application Password where the site allows (WordPress 5.7+ tells a password its own id), then removes the connection, with its sign-in. The answer says whether it was revoked, so Settings can ask the person to delete it in WordPress otherwise.
  • Connecting again with another site, user or password revokes the one it replaces. The same one typed again isn't revoked.
  • If the new sign-in can't be kept, the connection is marked to connect again. Otherwise a send would use the old sign-in on the new site.

Sending (target: 'wordpress'; cms/wordpress-delivery.js). It uses the same package HTML, cap, batches and delivery rows as the webhook and Webflow.

  • A page never sent to the site becomes a new draft post: title, slug (WordPress makes it unique; empty, it makes one from the title), content and the meta description as the excerpt.
  • A page sent before updates the post its last send made on that site, while that post is still a draft (draft, pending). Its status isn't touched.
    • target_collection keeps the site's whole address, not its host. Two sites in folders of one domain, or of a multisite, number their posts each from 1.
    • 00294 lets the column take an address's length (2,048).
    • external_id keeps the post id.
  • A live post isn't written over. WordPress has no draft of a published post: writing to it puts the change live at once, and Send content from the Content Editor and Library to a CMS (webhook first, then WordPress and Webflow) #1331 sends drafts only.
    • When the page's post is published, scheduled or private, the page goes as a new draft post.
    • The send says so (live: true, for the web to show), and the person moves the text over by hand.
    • WordPress doesn't make drafts' slugs unique. So that draft, published as it is, would take the slug with "-2"; the web will say so.
  • A post in the trash, deleted, or another user's that this one can't edit (a connection made again with another user) gets a new one.
  • A refused sign-in marks the connection auth_failed (Settings asks to connect again) and stops a batch's remaining pages, as Webflow's does.
    • Only the connection as the send read it is marked (updated_at), so a batch still going with the old password doesn't mark a connection made again meanwhile.
  • JSON-LD is left out of the post (changed.jsonLd counts the blocks).
    • For users without unfiltered HTML (Authors, Contributors, multisite, DISALLOW_UNFILTERED_HTML), kses strips the <script> tags but leaves the JSON in the post as text.
    • Schema on WordPress belongs to the site's SEO plugin. The docs will say so.

Calls go through the connectors' HTTP client (connectors/http.js): public https only, every resolved address checked, no redirect followed, a POST never sent twice, and errors that name the method and path only.

Migration 00294.

  • brand_cms_connections:
    • takes wordpress, with site_url (https) and account (the user);
    • Composio's ids are now Webflow's only (brand_cms_connections_provider_fields asks each provider for its own fields).
  • brand_cms_credentials (service role only, removed with its connection).
  • content_draft_deliveries.target: adds wordpress.
  • reserve_content_deliveries: same signature; a page already queued for the same CMS, Webflow or WordPress, isn't sent there again meanwhile.
  • schema.sql is rebuilt.

Code.

  • content-delivery.js: the Webflow-only webflow connection passed around is now native, one entry per CMS (NATIVE: label, connection check, send). The webhook path is unchanged.
  • routes/cms-wordpress.js: GET, POST and DELETE /api/cms/brands/:brandId/wordpress. Members read; admins and managers connect and disconnect. It reuses assertWriter and brandOf from cms.js.
  • .env.example: CONNECTOR_CREDENTIALS_KEY covers WordPress too. Without it, WordPress answers "not set up" (503) and everything else works as before.

Next: the published state (a post put live → the page Published at its link, as #1509 does for Webflow), then the web (Settings card and the Send dialog's target) and the docs.

Related issue

Part of #1331 (phase 2, native connectors: WordPress).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/lib/cms/wordpress.test.js src/lib/cms/wordpress-delivery.test.js src/lib/cms/credentials.test.js src/routes/cms-wordpress.test.js src/lib/content-delivery.test.js src/routes/cms.test.js. The WordPress API tests run against the connectors' fake API (connectors/testing.js), with no network.
  2. With a real site (gkhngyk), with CONNECTOR_CREDENTIALS_KEY set and 00294 applied:
    • Make an Application Password under Users › Profile.
    • POST /api/cms/brands/<brand>/wordpress { siteUrl, username, password } → the connection.
    • POST /api/content-drafts/send { brandId, target: 'wordpress', pages: [...] } → a draft post. Send it again → the same post, updated. Publish it in WordPress and send again → a new draft, live: true.
    • DELETE → the password is gone from the profile.

Migration 00294 was run twice in a row on the dev DB inside a rolled-back transaction. A WordPress row without its site is refused, a WordPress row with one is taken, and neither anon nor authenticated can read brand_cms_credentials. Not applied for good yet: it goes on the dev DB with the web PR.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Server only: npm run format, npm run lint and npm test (2,956 tests) in server/, and bash supabase/build-schema.sh. I ran them again after the pre-push review's fixes. The new checks fail without their fix: the password sent before the site answered as WordPress, and the dropped header read as a wrong password.

CONNECTORS.md's review checklist, as it applies to a CMS:

  • Least access: a user who can write posts. An Author is enough (Settings will suggest a separate Author user), and nothing more is asked.
  • Credentials live only in the credential store: none is in code, logs, error messages, fixtures or this PR. The key goes in a header.
  • No personal data is read or kept: the user's login name only, to show which user is connected.
  • Removal: disconnect, and a sign-in replaced, revoke the Application Password where the site allows.
  • Rate limits: every call goes through the connectors' client. A batch is 25 pages at most, with the send's 2-second pause between them.

🤖 Generated with Claude Code

…ord and send pages to it as draft posts (ansvisor#1331)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ss-server

# Conflicts:
#	server/src/lib/content-delivery.test.js
#	supabase/schema.sql
cihan-gyk and others added 2 commits October 28, 2026 03:07
… has ended

Since ansvisor#1589 a workspace whose plan has ended can't write, but taking back an
outside account's access stays open (COST_STOPPING), as Webflow's disconnect
does. WordPress's disconnect revokes the Application Password where the site
allows, so it joins the list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (ddc01c9). schema.sql was rebuilt with build-schema.sh; 00294 and 00295 are still free on main. One fix: since #1589, an ended workspace can't write, and Webflow's disconnect is in COST_STOPPING while WordPress's wasn't, so it would have answered 402. DELETE of the WordPress connection is now in COST_STOPPING (test updated); connect, save and send still answer 402, as Webflow's do. Checks: typecheck on every web tip, the server suite at #1579 (3,522 tests), and the whole web suite (4,438 tests) and yarn build at #1580.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with follow-ups

Reviewed this PR's own change (main → ddc01c9, read as merged on main cfd8a35). It merges clean on main (no conflicts).

What I checked

  • Outbound requests. Every call to the site goes through the connectors' client (connectors/http.js): https only, standard port only, every resolved address checked public inside the connection's own lookup (so a name can't resolve public for a check and private for the request), IP literals checked before connecting, no redirect followed (a 3xx becomes "use the address it goes to"), 30 s per attempt, 20 MB cap on the decoded body. siteAddress() refuses http, a port, and a user or password in the address before anything is sent. Post ids and the Application Password uuid are validated before they go in a path.
  • The sign-in. The password is checked with the site, then sealed with AES-256-GCM under CONNECTOR_CREDENTIALS_KEY, bound to cms:<connection id> (lib/cms/credentials.js), in brand_cms_credentials, which only the service role can read. The GET answer (shape) never carries it; errors are logged by name only; the messages the browser sees name the host at most. The password goes to a site only once it answers as WordPress (or keeps its API from visitors with a 401/403).
  • Who can do what. Connect and disconnect check assertWriter (admins and managers of the brand's organization) on the server; reading the connection checks assertBrandAccess. Every query is by the brand id after that check, so another organization's connection can't be read or changed. Disconnect is open after a plan ends (COST_STOPPING) and revokes the Application Password where the site allows; connect needs an active plan.
  • HTML sent. cleanPublishHtml already drops every script but JSON-LD, frames, forms, event handlers and unsafe link schemes; toWordPressHtml then takes the JSON-LD out too.
  • Sending. A second send of a page to WordPress while one is queued is refused under the reserve lock (00294); a page whose post is live goes as a new draft post instead of overwriting the live one; a refused sign-in marks the connection (only the one the send read) and stops the rest of a batch.
  • Migration 00294 read in full (notes below).
  • Tests: full server suite on the merged stack, 272 files, 3,773 passed. eslint and prettier clean on every touched file.

Migration 00294

  • brand_cms_connections takes wordpress, with site_url (https only, ≤ 2048) and account; a check makes each provider carry its own fields, so Webflow rows still need their Composio ids. The new nullable columns don't rewrite the table; the added checks scan a small table once.
  • brand_cms_credentials: RLS on, no policies, all privileges revoked from public, anon and authenticated, granted to service_role only, removed with its connection.
  • reserve_content_deliveries keeps its signature, security definer with search_path = public, and execute for service_role only; the only change is that WordPress gets the same "already queued" refusal as Webflow.
  • The number is free on main (00293 and 00296 are taken, 00294 isn't). Applying it after 00296–00374 is fine: nothing later touches these objects.

Before merging

  • Order: apply 00294, deploy the API, then merge the web parts (#1571/#1572). Without the migration this API answers 500 on the WordPress routes; without this API, the web's WordPress card says it can't read the connection, and the Send dialog stays on the webhook.
  • CONNECTOR_CREDENTIALS_KEY must be set on the API (it already is wherever store connections work); without it the card says WordPress isn't set up.

Follow-ups

  1. toWordPressHtml matches type="application/ld+json" exactly, while cleanPublishHtml trims it first. A script typed " application/ld+json " goes into the post (inert, but shown as text to users without unfiltered HTML). Trim as isJsonLd does.
  2. A connect can take minutes on a slow site: checkSite makes up to four calls, and the client retries a GET that times out (30 s each, three retries). A shorter timeout and no retries for the connect check would answer sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants