Files
BetterDesk/web-nodejs/views/errors/404.ejs
T
UNITRONIX e11f7865c6 fix(panel): render 403/404/500 without i18n locals
Refs #513

A user denied by a panel section policy got Express's bare "Internal Server
Error" instead of a 403 page, so the account, the login and the server all
looked broken at once.

Two independent causes, both fixed:

  - middleware order: panelAccessGuard renders errors/403 on a denial, but
    initI18n() was mounted after it, so res.locals.lang, appName and _()
    did not exist yet and the template threw
  - the error templates used lang, appName and _() unguarded, so the
    subsequent 500.ejs render threw the same way and Express fell back to
    its default page

initI18n() now mounts before loadEffectivePermissions / loadEffectivePolicy /
panelAccessGuard, which is safe because it still runs after cookieParser()
and the session middleware. The three error templates compute defensive
locals, so they render with no locals at all; 403.ejs falls back to the
title/message the guard already passes, and 500.ejs still reveals details
only under NODE_ENV=development.

Covered by tests/errorTemplates.render.test.js, which renders each template
with ejs.render(src, {}) so an unguarded local cannot come back.

Reported-by: @mh254

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow); muopc (@muopc)
2026-11-20 08:57:08 +01:00

78 lines
2.8 KiB
HTML

<%
/*
* Defensive locals: this template must render even when it is used from a
* path that has no i18n/branding locals (see issue #513). Never assume a
* local exists here - an unguarded reference would turn one error page into
* a second, unrenderable one.
*/
var viewLang = (typeof lang !== 'undefined' && lang) ? lang : 'en';
var viewAppName = (typeof appName !== 'undefined' && appName) ? appName : 'BetterDesk';
var viewCacheVersion = (typeof cacheVersion !== 'undefined') ? cacheVersion : '';
var viewBrandingRevision = (typeof brandingRevision !== 'undefined')
? brandingRevision
: viewCacheVersion;
var viewT = (typeof _ === 'function')
? _
: function (key, fallback) { return fallback || key; };
%>
<!DOCTYPE html>
<html lang="<%= viewLang %>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 - Not Found | <%= viewAppName %></title>
<link rel="icon" type="image/svg+xml" href="/branding/favicon.svg">
<link rel="stylesheet" href="/css/main.css?v=<%= viewCacheVersion %>">
<link rel="stylesheet" href="/css/theme.css?v=<%= viewCacheVersion %>">
<link rel="stylesheet" href="/css/branding.css?v=<%= viewBrandingRevision %>">
<style>
.error-page {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
padding: var(--space-lg);
}
.error-container {
max-width: 400px;
}
.error-code {
font-size: 120px;
font-weight: 700;
color: var(--accent-blue);
line-height: 1;
margin-bottom: var(--space-md);
}
.error-title {
font-size: var(--font-size-2xl);
font-weight: 600;
margin-bottom: var(--space-sm);
}
.error-message {
color: var(--text-secondary);
margin-bottom: var(--space-xl);
}
.error-icon {
font-size: 64px;
color: var(--text-tertiary);
margin-bottom: var(--space-md);
}
</style>
</head>
<body>
<div class="error-page">
<div class="error-container">
<span class="material-icons error-icon">search_off</span>
<div class="error-code">404</div>
<h1 class="error-title"><%= viewT('errors.not_found_title', 'Not Found') %></h1>
<p class="error-message"><%= viewT('errors.not_found_message', 'The page you are looking for does not exist.') %></p>
<a href="/" class="btn btn-primary">
<span class="material-icons">home</span>
<%= viewT('errors.go_home', 'Go Home') %>
</a>
</div>
</div>
</body>
</html>