Skip to content

Commit ffd0403

Browse files
authored
fix: always regenerate encrypted OAuth secrets in release build (#890)
The AES key for inc/stuff.php is derived from sha256(inc/class-addon-repository.php). Any change to that file — even whitespace — changes the key and makes the committed ciphertext undecryptable, so the OAuth flow to ultimatemultisite.com sends empty client_id/client_secret and the server replies with: {"error":"invalid_client","error_description":"No client id supplied"}. encrypt-secrets.php (run via 'npm run prearchive' in the release workflow) had an mtime-based shortcut that skipped regeneration when filemtime(class-addon-repository.php) <= filemtime(stuff.php). In CI, actions/checkout normalises every file's mtime to the checkout time, so the shortcut always fired and the stale ciphertext shipped unchanged. Remove the mtime guard: regenerate the ciphertext unconditionally whenever MU_CLIENT_ID/MU_CLIENT_SECRET are supplied.
1 parent d666041 commit ffd0403

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

encrypt-secrets.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ function encryptValue($plaintext, $key) {
2323

2424
$target_file = 'inc/stuff.php';
2525

26-
if (!file_exists($target_file) || filemtime($filename) > filemtime($target_file)) {
27-
file_put_contents($target_file, "<?php\nreturn ".var_export([
28-
encryptValue($client_id, $key),
29-
encryptValue($client_secret, $key),
30-
], true).';');
31-
echo "Updated $target_file\n";
32-
} else {
33-
echo "$target_file is up to date\n";
34-
}
26+
// Always regenerate the ciphertext when credentials are supplied.
27+
//
28+
// The AES key is derived from the sha256 of inc/class-addon-repository.php
29+
// (see Addon_Repository::decrypt_value). Any change to that file — including
30+
// a whitespace/coding-standards fix — changes the key and makes previously
31+
// committed ciphertext undecryptable. An mtime-based "up to date" shortcut
32+
// was used here previously, but in CI (actions/checkout normalises mtimes)
33+
// it always reported "up to date" and shipped stale ciphertext, producing
34+
// `{"error":"invalid_client","error_description":"No client id supplied"}`
35+
// on every customer's OAuth flow. Regenerate unconditionally.
36+
file_put_contents($target_file, "<?php\nreturn ".var_export([
37+
encryptValue($client_id, $key),
38+
encryptValue($client_secret, $key),
39+
], true).';');
40+
echo "Updated $target_file\n";

0 commit comments

Comments
 (0)