Skip to content

Fail release builds with empty OAuth secret#40

Open
mokagio wants to merge 3 commits into
mainfrom
mokagio/guard-empty-oauth-secret
Open

Fail release builds with empty OAuth secret#40
mokagio wants to merge 3 commits into
mainfrom
mokagio/guard-empty-oauth-secret

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 14, 2026

Rationale

In #13's review, @iangmaia flagged that the Makefile recipe injecting WPCOMOAuthClientSecret had no validation: if WPCOM_OAUTH_CLIENT_SECRET was unset (or its file path empty) the plutil -replace call still ran with an empty string, so the build could happily produce a signed-and-notarized artifact that authenticates as nobody. CI's .buildkite/commands/build.sh invokes make release directly, so the upfront env check in Tools/manual-release.sh didn't cover it.

This PR extracts the post-build verification into Tools/verify-oauth-secret.sh and makes notarize-app depend on it, so every artifact-producing path (make zip, make release, Tools/manual-release.sh) runs the same check. The default make target stays untouched — dev iteration without a secret keeps working.

Gotcha

The inline check that used to live in manual-release.sh had a latent bug:

SECRET_LENGTH=$(plutil -extract WPCOMOAuthClientSecret raw -o - "$plist" | wc -c | tr -d ' ')
[ "$SECRET_LENGTH" -eq 0 ] && die ...

plutil -extract … raw emits a trailing newline, so wc -c returned 1 for the empty case and the guard never fired. The new script uses secret=$(plutil …) + [ -z "$secret" ]; command substitution strips the newline, so both the empty-string and missing-key cases trip the check. See the commit body for more.

How to test

From a clean tree (in the worktree):

make clean && make verify-oauth-secret
# → build succeeds, then exits 1: "missing WPCOMOAuthClientSecret"

make clean && WPCOM_OAUTH_CLIENT_SECRET=test-value make verify-oauth-secret
# → build succeeds, verify exits 0 silently

make --dry-run release will show Tools/verify-oauth-secret.sh running after the build and before Tools/notarize.sh, so a missing secret fails fast (no wasted notary-service round-trip).

CI on this branch exercises the happy path.

CI's `make release` had no guard against a missing
`WPCOM_OAUTH_CLIENT_SECRET` env var: the Makefile recipe wrote whatever
`$secret` ended up being (possibly empty) into `Info.plist` and signed
the bundle, so a misconfigured agent could ship a notarized artifact
that authenticates as nobody.

Extract the post-build check into `Tools/verify-oauth-secret.sh` and
hook it into `notarize-app` so every release path (`make zip`, `make
release`, `Tools/manual-release.sh`) runs the same verification, after
build and before the notary submission.

The inline check that previously lived in `manual-release.sh` had a
latent bug: `plutil -extract ... raw` appends a trailing newline, so
`wc -c` returned 1 for the empty-string case and the guard never
fired. The new script uses command substitution + `[ -z ]`, which
strips the newline and behaves correctly for both empty-string and
missing-key cases.

See #13 (comment).

---

Generated with the help of Claude Code, https://claude.com/claude-code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 14, 2026 04:48
@mokagio mokagio self-assigned this May 14, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a shared, post-build verification step to ensure release/packaging builds fail if the WordPress.com OAuth client secret wasn’t injected into the app bundle, preventing signed/notarized artifacts that cannot authenticate.

Changes:

  • Added Tools/verify-oauth-secret.sh to validate WPCOMOAuthClientSecret in the built app’s Info.plist.
  • Updated Tools/manual-release.sh to call the new verifier instead of duplicating the check inline.
  • Updated Makefile to add a verify-oauth-secret target and make notarize-app depend on it so all artifact-producing paths run the check.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Tools/verify-oauth-secret.sh New script to validate the OAuth secret exists and is non-empty in the built app bundle.
Tools/manual-release.sh Replaces inline secret validation with a call to the shared verifier script.
Makefile Adds verify-oauth-secret target and wires it into the notarization/release chain.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Tools/verify-oauth-secret.sh Outdated
Comment on lines +31 to +35
secret=$(plutil -extract WPCOMOAuthClientSecret raw -o - "$PLIST" 2>/dev/null || true)
if [ -z "$secret" ]; then
echo "Error: $APP_BUNDLE is missing WPCOMOAuthClientSecret in Info.plist." >&2
echo "Set WPCOM_OAUTH_CLIENT_SECRET or pass WPCOM_OAUTH_CLIENT_SECRET_FILE before building." >&2
exit 1
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point — confirmed WPCOMClient.swift trims clientSecret with .whitespacesAndNewlines, so a whitespace-only value would authenticate as nobody just like an empty one. Fixed in 12eca98: the check now strips all whitespace before the -z test, so empty and whitespace-only values both fail. Verified against empty, whitespace-only, and real-value fixtures.

Posted by Claude (Opus 4.7) on behalf of @mokagio with approval.

mokagio and others added 2 commits May 14, 2026 15:00
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The app trims `WPCOMOAuthClientSecret` with `.whitespacesAndNewlines`
when reading it (`WPCOMClient.swift` `clientSecret`), so a
whitespace-only plist value authenticates as nobody just like an empty
one. Strip all whitespace before the emptiness test so the guard
catches that case too.

---

Generated with the help of Claude Code, https://claude.com/claude-code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mokagio mokagio requested review from iangmaia and twstokes May 14, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants