WordPress makes two assumptions this project cannot accept: that identity comes from an email address, and that a site lives at one server. Both are things somebody else can take away — a mailbox is rented from a provider who can close it or be compelled to open it, and a server is one seizure from being gone. Sirius Press replaces the first and hedges the second. Signing in means signing a challenge with the key that controls a CashAddress. The address is recovered from the signature, so nothing is typed but the signature itself, and the result is an ordinary WordPress session cookie — roles, capabilities, nonces and the REST API never learn the login was different. Three ways to produce one: a wallet the browser already exposes, a phrase used once in the page and wiped, or a signature pasted in from any BIP-137 wallet, which needs no JavaScript and lets the key stay on a machine that never touches the web. There is no password reset, and the recovery page says so plainly rather than offering a form that cannot work. A reset mechanism is by construction a way to take an account from its owner, and it is always easier to attack than the cryptography it bypasses. Publishing a post also exports it as static HTML to the name's storage on Sia, signed by the key that owns the name, so the site keeps answering when the server does not. Email as a feature is untouched. wp_mail() still works, SMTP still sends, and contact forms still deliver to addresses real people typed. Only mail to the site's own unroutable placeholder addresses is diverted to an in-app inbox. The objection was to email as identity, not to email. Core is pinned and patched rather than vendored. WordPress 7.1.1 is 149 MB and 5,008 files; the fork's entire core diff is 75 lines in wp-admin/install.php. Carrying the former to express the latter would bury the patch where nobody reviews it and make every clone of the monorepo pay for it. Upstream releases still merge through tools/update-wordpress.sh, which reapplies the series and says exactly which hunk needs a human. The cryptography is implemented twice — PHP on the server, JavaScript in the page — because the server must verify and the browser must sign. Both are pinned against libauth, the library the Sirius portal wallet and the BNS gateway already use, so a disagreement of one byte fails the test suite rather than presenting as a rejected login at three in the morning. 132 checks, no framework, about a second.
131 lines
6.6 KiB
PHP
131 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* URL-to-path mapping and link rewriting.
|
|
*
|
|
* A wrong answer here is silent. Two pages that map to one path means one
|
|
* quietly overwrites the other, and nobody finds out until a reader opens an
|
|
* article and gets a different one. A link rewritten wrongly means the static
|
|
* copy points back at the origin server it exists to make optional.
|
|
*
|
|
* So the cases below are mostly the awkward ones: a URL that looks like a file
|
|
* but is a page, a path the gateway would refuse, a document deep in a tree
|
|
* linking back up to an asset at the root.
|
|
*
|
|
* @package SiriusPress
|
|
*/
|
|
|
|
require_once __DIR__ . '/bootstrap.php';
|
|
|
|
T::group( 'gateway path rules' );
|
|
|
|
T::is( SP_Gateway::clean_path( '/blog/hello/index.html' ), 'blog/hello/index.html', 'a leading slash is dropped' );
|
|
T::is( SP_Gateway::clean_path( 'blog//hello///index.html' ), 'blog/hello/index.html', 'repeated slashes collapse' );
|
|
T::is( SP_Gateway::clean_path( 'a/../../etc/passwd' ), '', 'traversal is refused' );
|
|
T::is( SP_Gateway::clean_path( 'blog/' ), '', 'a trailing slash is refused — the gateway stores objects, not directories' );
|
|
T::is( SP_Gateway::clean_path( '' ), '', 'an empty path is refused' );
|
|
T::is( SP_Gateway::clean_path( 'café/index.html' ), '', 'characters the gateway rejects are refused here' );
|
|
T::is( SP_Gateway::clean_path( str_repeat( 'a', 201 ) ), '', 'an over-long path is refused' );
|
|
T::is( SP_Gateway::clean_path( 'wp-content/themes/x/style.css' ), 'wp-content/themes/x/style.css', 'an asset path survives' );
|
|
|
|
T::is( SP_Gateway::mime_for( 'index.html' ), 'text/html; charset=utf-8', 'html content type' );
|
|
T::is( SP_Gateway::mime_for( 'app.CSS' ), 'text/css; charset=utf-8', 'extensions are matched case-insensitively' );
|
|
T::is( SP_Gateway::mime_for( 'thing.unknown' ), 'application/octet-stream', 'an unknown extension falls back' );
|
|
|
|
T::group( 'URL to bucket path' );
|
|
|
|
$cases = array(
|
|
'/' => 'index.html',
|
|
'' => 'index.html',
|
|
'/hello-world/' => 'hello-world/index.html',
|
|
'/hello-world' => 'hello-world/index.html',
|
|
'/blog/2026/09/a-post/' => 'blog/2026/09/a-post/index.html',
|
|
'/robots.txt' => 'robots.txt',
|
|
'/wp-content/themes/x/style.css' => 'wp-content/themes/x/style.css',
|
|
'/sitemap.xml' => 'sitemap.xml',
|
|
// Ends in a slash, so it is a page whose name happens to contain a dot —
|
|
// not a file called "about.us".
|
|
'/about.us/' => 'about.us/index.html',
|
|
);
|
|
foreach ( $cases as $url => $expected ) {
|
|
T::is( SPE_Mapper::path_for_url_path( $url ), $expected, "'{$url}' maps to '{$expected}'" );
|
|
}
|
|
|
|
T::ok( SPE_Mapper::is_asset( 'wp-content/x.css' ), 'a stylesheet is an asset' );
|
|
T::ok( SPE_Mapper::is_asset( 'a/b/photo.JPG' ), 'an uppercase extension still reads as an asset' );
|
|
T::ok( ! SPE_Mapper::is_asset( 'blog/post/index.html' ), 'a page is not an asset' );
|
|
|
|
// Distinct pages must never land on one path.
|
|
$paths = array();
|
|
foreach ( array( '/a/', '/b/', '/a/b/', '/a/b/c/', '/a.html', '/ab/' ) as $url ) {
|
|
$paths[] = SPE_Mapper::path_for_url_path( $url );
|
|
}
|
|
T::is( count( array_unique( $paths ) ), count( $paths ), 'six distinct URLs give six distinct paths' );
|
|
|
|
// `/a/` and `/a/index.html` are the same page in WordPress and are SUPPOSED to
|
|
// share a path — this records that as intended, not as the collision above.
|
|
T::is(
|
|
SPE_Mapper::path_for_url_path( '/a/' ),
|
|
SPE_Mapper::path_for_url_path( '/a/index.html' ),
|
|
'a directory URL and its explicit index are one page'
|
|
);
|
|
|
|
T::group( 'document-relative links' );
|
|
|
|
$relative = array(
|
|
// from to expected
|
|
array( 'index.html', 'about/index.html', 'about/index.html' ),
|
|
array( 'about/index.html', 'index.html', '../index.html' ),
|
|
array( 'blog/post/index.html', 'wp-content/app.css', '../../wp-content/app.css' ),
|
|
array( 'blog/post/index.html', 'blog/other/index.html', '../other/index.html' ),
|
|
array( 'a/b/c/index.html', 'a/b/c/style.css', 'style.css' ),
|
|
array( 'index.html', 'index.html', 'index.html' ),
|
|
);
|
|
foreach ( $relative as $case ) {
|
|
list( $from, $to, $expected ) = $case;
|
|
T::is( SPE_Renderer::relative( $from, $to ), $expected, "{$from} -> {$to}" );
|
|
}
|
|
|
|
T::group( 'rewriting a page' );
|
|
|
|
$html = '<!doctype html><html><head>'
|
|
. '<link rel="stylesheet" href="https://example.test/wp-content/themes/x/style.css?ver=1.2">'
|
|
. '<link rel="canonical" href="https://example.test/blog/hello/">'
|
|
. '</head><body>'
|
|
. '<a href="https://example.test/">Home</a>'
|
|
. '<a href="https://example.test/about/">About</a>'
|
|
. '<a href="https://elsewhere.example/offsite">Offsite</a>'
|
|
. '<img src="//example.test/wp-content/uploads/pic.png" alt="">'
|
|
. '<a href="https://example.test/blog/hello/#notes">Notes</a>'
|
|
. '</body></html>';
|
|
|
|
$result = SPE_Renderer::rewrite( $html, 'blog/hello/index.html' );
|
|
$out = $result['html'];
|
|
|
|
T::ok( false === strpos( $out, 'https://example.test' ), 'no absolute self-links remain' );
|
|
T::ok( false !== strpos( $out, 'href="../../index.html"' ), 'the home link became document-relative' );
|
|
T::ok( false !== strpos( $out, 'href="../../about/index.html"' ), 'an internal page link became relative' );
|
|
T::ok( false !== strpos( $out, 'href="https://elsewhere.example/offsite"' ), 'an external link is left alone' );
|
|
T::ok(
|
|
false !== strpos( $out, 'href="../../wp-content/themes/x/style.css"' ),
|
|
'the ?ver= query is dropped from an asset, which the bucket stores once'
|
|
);
|
|
T::ok( false !== strpos( $out, 'src="../../wp-content/uploads/pic.png"' ), 'a protocol-relative URL is rewritten too' );
|
|
T::ok( false !== strpos( $out, 'href="index.html#notes"' ), 'a fragment survives rewriting' );
|
|
|
|
T::ok( isset( $result['assets']['wp-content/themes/x/style.css'] ), 'the stylesheet was collected for export' );
|
|
T::ok( isset( $result['assets']['wp-content/uploads/pic.png'] ), 'the image was collected for export' );
|
|
T::is(
|
|
$result['assets']['wp-content/themes/x/style.css'],
|
|
'https://example.test/wp-content/themes/x/style.css',
|
|
'a collected asset carries the URL to fetch it from'
|
|
);
|
|
T::ok( ! isset( $result['assets']['about/index.html'] ), 'a page is not collected as an asset' );
|
|
|
|
// The exporter's own marker must never survive into a published page: every
|
|
// internal link would carry it, and the published copy would then be asking
|
|
// for the export-rendered variant of every page.
|
|
$flagged = '<a href="https://example.test/about/?sirius_export=abc123">About</a>';
|
|
$rewrote = SPE_Renderer::rewrite( $flagged, 'index.html' )['html'];
|
|
T::ok( false === strpos( $rewrote, 'sirius_export' ), 'the export marker is stripped' );
|
|
|
|
exit( T::summary() );
|