Skip to content

Fix handleUnauthorized serving old mashlib when mashlibModule configured - #147

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-143-handleunauthorized-mashlib-module
Mar 3, 2026
Merged

Fix handleUnauthorized serving old mashlib when mashlibModule configured#147
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-143-handleunauthorized-mashlib-module

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Summary

  • Add generateModuleDatabrowserHtml import to auth middleware
  • Add mashlibModule check in handleUnauthorized() to match the ternary pattern used in resource handlers

Problem

When mashlibModule is configured, unauthenticated/unauthorized requests still get the classic mashlib HTML (referencing local /mashlib.min.js and /mash.css) instead of the ES module HTML. This causes 404 errors since the local mashlib files aren't installed.

Test plan

  • Set mashlibModule in config, visit a resource without auth → mashlib-next module HTML served
  • With mashlibCdn config → classic CDN mashlib HTML still works
  • With solidosUi config → SolidOS UI HTML still works
  • With mashlib: true (local) → classic local mashlib HTML still works

Fixes #143

handleUnauthorized() didn't check request.mashlibModule, always falling
back to generateDatabrowserHtml which references local /mashlib.min.js
and /mash.css (404 when not installed locally).

Add generateModuleDatabrowserHtml import and mashlibModule check to
match the same ternary pattern used in the resource handlers.

Fixes #143

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes unauthorized HTML responses to respect mashlibModule configuration, aligning handleUnauthorized() behavior with the mashlib selection logic used in resource handlers (avoiding broken classic mashlib asset references when only the ES module URL is configured).

Changes:

  • Import generateModuleDatabrowserHtml into the auth middleware.
  • Update handleUnauthorized() to serve module-based mashlib HTML when request.mashlibModule is set (with SolidOS UI still taking precedence).
  • Preserve existing classic mashlib behavior (local/CDN) as the fallback.

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

Comment thread src/auth/middleware.js
Comment on lines +129 to +131
: request.mashlibModule
? generateModuleDatabrowserHtml(request.mashlibModule)
: generateDatabrowserHtml(request.url, request.mashlibCdn ? request.mashlibVersion : null);

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

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

generateModuleDatabrowserHtml expects a string URL (it calls .replace(/\.js$/, ...)). request.mashlibModule can be a non-string truthy value (e.g., true via JSS_MASHLIB_MODULE=true because env parsing coerces "true" to boolean), which would throw a TypeError here and turn 401/403 into a 500. Consider validating request.mashlibModule is a non-empty string before calling, and/or rejecting invalid config earlier with a clear startup error.

Copilot uses AI. Check for mistakes.
Comment thread src/auth/middleware.js
Comment on lines 125 to 132
if (request.mashlibEnabled) {
// Use SolidOS UI if enabled, otherwise fallback to classic mashlib
// Use SolidOS UI if enabled, ES module if configured, otherwise classic mashlib
const html = request.solidosUiEnabled
? generateSolidosUiHtml()
: generateDatabrowserHtml(request.url, request.mashlibCdn ? request.mashlibVersion : null);
: request.mashlibModule
? generateModuleDatabrowserHtml(request.mashlibModule)
: generateDatabrowserHtml(request.url, request.mashlibCdn ? request.mashlibVersion : null);
return reply.code(statusCode).type('text/html').send(html);

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

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

This change adds a new HTML response path for unauthenticated requests when mashlibModule is configured, but there doesn't appear to be test coverage asserting which HTML wrapper is served for 401/403 with Accept: text/html. Adding an integration test would help prevent regressions across mashlibModule / mashlibCdn / solidosUi configurations.

Copilot uses AI. Check for mistakes.
@melvincarvalho
melvincarvalho merged commit 30368e7 into gh-pages Mar 3, 2026
4 checks passed
@melvincarvalho
melvincarvalho deleted the issue-143-handleunauthorized-mashlib-module branch March 3, 2026 09:18
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.

handleUnauthorized serves old mashlib HTML when mashlibModule is configured

2 participants