Problem
Harper's app-port authentication middleware resolves Authorization before route ownership is known. In Harper 5.2.6, an invalid/non-Harper Basic credential causes security/auth.ts to return 401 immediately. Downstream route matching never runs.
This prevents a Harper application from composing these two valid requirements:
- Harper authentication and native route ownership run before an application catch-all, so native/public routes such as status and Harper-owned resources never reach application authorization middleware.
- Unmatched application routes can use their own standard
Authorization scheme. In this case WordPress Application Passwords, WooCommerce REST Basic credentials, and Bearer tokens must reach the Woo proxy and origin byte-for-byte.
Hoisting the catch-all with { before: "authentication" } preserves WordPress credentials but lets it claim Harper-owned routes. Ordering it after rest restores native route ownership but Harper rejects WordPress credentials first. URL exemptions, carrier headers, renamed credentials, and middleware header mutation are not acceptable architecture.
Reproduction and exact 5.2.6 code-path evidence are tracked in HarperFast/harper-woo-cache#297 and its draft PR #298. That PR includes tools/repro/harper-auth-ordering.mjs.
Required design
Authentication must run first, but credential rejection must be deferred until route ownership is known:
- Valid Harper credentials authenticate normally and populate the Harper principal.
- Missing credentials continue anonymously as today.
- A syntactically valid but unrecognized credential must not terminate the global middleware chain before routing. Preserve the original
Authorization header unchanged and continue with no Harper principal plus an internal authentication-failure state.
- If a downstream Harper-owned route requires a Harper principal, that owning layer returns the normal generic unauthorized response. Invalid credentials must never grant access or downgrade a protected Harper route into a public route.
- If Harper REST/resource matching finds no owner, an application catch-all may receive the untouched header and apply its own authentication scheme.
- Native public routes such as status remain reachable without application-specific edge credentials.
- Internal authentication faults must remain fail-closed. Do not treat storage/configuration/runtime failures as ordinary unknown credentials.
Prefer a generally reusable core contract over Woo- or path-specific behavior. If compatibility requires a setting, it must be explicit, documented, secure by default, and usable by a deployed application/cluster without patching node_modules.
Acceptance criteria
Integration dependency
HarperFast/harper-woo-cache#297 / PR #298 must not ship its ordering-only change until this core capability is available in the deployed Harper version and the application enables/uses it. Otherwise /status is repaired by reintroducing the WordPress authentication P1.
Priority
P1. Current production candidate cannot keep both monitored native endpoints and authenticated WordPress/Woo routes working under correct route ownership.
Problem
Harper's app-port
authenticationmiddleware resolvesAuthorizationbefore route ownership is known. In Harper 5.2.6, an invalid/non-Harper Basic credential causessecurity/auth.tsto return401immediately. Downstream route matching never runs.This prevents a Harper application from composing these two valid requirements:
Authorizationscheme. In this case WordPress Application Passwords, WooCommerce REST Basic credentials, and Bearer tokens must reach the Woo proxy and origin byte-for-byte.Hoisting the catch-all with
{ before: "authentication" }preserves WordPress credentials but lets it claim Harper-owned routes. Ordering it afterrestrestores native route ownership but Harper rejects WordPress credentials first. URL exemptions, carrier headers, renamed credentials, and middleware header mutation are not acceptable architecture.Reproduction and exact 5.2.6 code-path evidence are tracked in HarperFast/harper-woo-cache#297 and its draft PR #298. That PR includes
tools/repro/harper-auth-ordering.mjs.Required design
Authentication must run first, but credential rejection must be deferred until route ownership is known:
Authorizationheader unchanged and continue with no Harper principal plus an internal authentication-failure state.Prefer a generally reusable core contract over Woo- or path-specific behavior. If compatibility requires a setting, it must be explicit, documented, secure by default, and usable by a deployed application/cluster without patching
node_modules.Acceptance criteria
Authorizationbyte-for-byte unchanged.authentication -> rest -> application catch-all; no path exemption list, carrier header, header rename, or pre-auth credential-stripping shim is introduced.Integration dependency
HarperFast/harper-woo-cache#297 / PR #298 must not ship its ordering-only change until this core capability is available in the deployed Harper version and the application enables/uses it. Otherwise
/statusis repaired by reintroducing the WordPress authentication P1.Priority
P1. Current production candidate cannot keep both monitored native endpoints and authenticated WordPress/Woo routes working under correct route ownership.