Repository navigation
feat(cms): connect a brand's WordPress site with an Application Password and send pages to it as draft posts (#1331) - #1569
Conversation
…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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 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]>
|
Merged main forward (ddc01c9). |
gkhngyk
left a comment
There was a problem hiding this comment.
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 tocms:<connection id>(lib/cms/credentials.js), inbrand_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 checksassertBrandAccess. 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.
cleanPublishHtmlalready drops every script but JSON-LD, frames, forms, event handlers and unsafe link schemes;toWordPressHtmlthen 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_connectionstakeswordpress, withsite_url(https only, ≤ 2048) andaccount; 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 frompublic,anonandauthenticated, granted toservice_roleonly, removed with its connection.reserve_content_deliverieskeeps its signature,security definerwithsearch_path = public, and execute forservice_roleonly; 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_KEYmust be set on the API (it already is wherever store connections work); without it the card says WordPress isn't set up.
Follow-ups
toWordPressHtmlmatchestype="application/ld+json"exactly, whilecleanPublishHtmltrims it first. A script typed" application/ld+json "goes into the post (inert, but shown as text to users without unfiltered HTML). Trim asisJsonLddoes.- A connect can take minutes on a slow site:
checkSitemakes 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.
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).
/wp-adminand/wp-jsoncopied 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./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.users/me(context=edit) takes the sign-in.edit_posts.users/merefuses 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.htaccessline), rather than "wrong password".CONNECTOR_CREDENTIALS_KEY) in the newbrand_cms_credentials, which only the service role reads.cms:<connection id>, so it opens on its own connection only, never as another's or as a store source's.Sending (
target: 'wordpress';cms/wordpress-delivery.js). It uses the same package HTML, cap, batches and delivery rows as the webhook and Webflow.target_collectionkeeps 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.external_idkeeps the post id.live: true, for the web to show), and the person moves the text over by hand.auth_failed(Settings asks to connect again) and stops a batch's remaining pages, as Webflow's does.updated_at), so a batch still going with the old password doesn't mark a connection made again meanwhile.changed.jsonLdcounts the blocks).DISALLOW_UNFILTERED_HTML), kses strips the<script>tags but leaves the JSON in the post as text.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:wordpress, withsite_url(https) andaccount(the user);brand_cms_connections_provider_fieldsasks each provider for its own fields).brand_cms_credentials(service role only, removed with its connection).content_draft_deliveries.target: addswordpress.reserve_content_deliveries: same signature; a page already queued for the same CMS, Webflow or WordPress, isn't sent there again meanwhile.schema.sqlis rebuilt.Code.
content-delivery.js: the Webflow-onlywebflowconnection passed around is nownative, one entry per CMS (NATIVE: label, connection check, send). The webhook path is unchanged.routes/cms-wordpress.js:GET,POSTandDELETE /api/cms/brands/:brandId/wordpress. Members read; admins and managers connect and disconnect. It reusesassertWriterandbrandOffromcms.js..env.example:CONNECTOR_CREDENTIALS_KEYcovers 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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
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.CONNECTOR_CREDENTIALS_KEYset and 00294 applied: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
anonnorauthenticatedcan readbrand_cms_credentials. Not applied for good yet: it goes on the dev DB with the web PR.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Server only:
npm run format,npm run lintandnpm test(2,956 tests) inserver/, andbash 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:
🤖 Generated with Claude Code