mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-11-24 01:52:12 +00:00
e11f7865c6
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)
109 lines
4.0 KiB
HTML
109 lines
4.0 KiB
HTML
<%
|
|
/*
|
|
* Defensive locals: this template is the last-resort render, so it must never
|
|
* throw. It is reached when another page failed, and it is itself used by
|
|
* panelAccessGuard/503 paths that run before initI18n() (issue #513).
|
|
*/
|
|
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; };
|
|
var viewErrorText = '';
|
|
if (typeof error !== 'undefined' && error) {
|
|
viewErrorText = String(error.message || error);
|
|
}
|
|
%>
|
|
<!DOCTYPE html>
|
|
<html lang="<%= viewLang %>">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>500 - Server Error | <%= 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-red);
|
|
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);
|
|
}
|
|
.error-details {
|
|
background: var(--bg-tertiary);
|
|
border: 1px solid var(--border-primary);
|
|
border-radius: var(--radius-md);
|
|
padding: var(--space-md);
|
|
margin-bottom: var(--space-lg);
|
|
text-align: left;
|
|
font-family: var(--font-mono);
|
|
font-size: var(--font-size-sm);
|
|
color: var(--accent-red);
|
|
overflow-x: auto;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="error-page">
|
|
<div class="error-container">
|
|
<span class="material-icons error-icon">error</span>
|
|
<div class="error-code">500</div>
|
|
<h1 class="error-title"><%= viewT('errors.server_error_title', 'Server Error') %></h1>
|
|
<p class="error-message"><%= viewT('errors.server_error_message', 'Something went wrong. Please try again.') %></p>
|
|
|
|
<% if (viewErrorText && typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development') { %>
|
|
<div class="error-details">
|
|
<pre><%= viewErrorText %></pre>
|
|
</div>
|
|
<% } %>
|
|
|
|
<div class="flex gap-sm justify-center">
|
|
<button id="btn-retry" class="btn btn-secondary">
|
|
<span class="material-icons">refresh</span>
|
|
<%= viewT('errors.try_again', 'Try Again') %>
|
|
</button>
|
|
<a href="/" class="btn btn-primary">
|
|
<span class="material-icons">home</span>
|
|
<%= viewT('errors.go_home', 'Go Home') %>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script nonce="<%= typeof cspNonce !== 'undefined' ? cspNonce : '' %>">
|
|
document.getElementById('btn-retry').addEventListener('click', function() { location.reload(); });
|
|
</script>
|
|
</body>
|
|
</html>
|