feat(auth): require changing default admin password (#778)

This commit is contained in:
h44z
2026-11-09 19:57:23 +01:00
committed by GitHub
parent 137286d46b
commit 276f120b60
30 changed files with 641 additions and 90 deletions
+7
View File
@@ -6,6 +6,7 @@ import { authStore } from "./stores/auth";
import { securityStore } from "./stores/security";
import { settingsStore } from "@/stores/settings";
import { Notifications } from "@kyvg/vue3-notification";
import DefaultPasswordModal from "@/components/DefaultPasswordModal.vue";
const appGlobal = getCurrentInstance().appContext.config.globalProperties
const auth = authStore()
@@ -197,9 +198,15 @@ const userDisplayName = computed(() => {
</nav>
<div class="container mt-5 flex-shrink-0">
<div class="alert alert-warning mb-4" v-if="auth.IsAuthenticated && auth.DefaultPasswordInUse">
<h4 class="alert-heading"><i class="fa-solid fa-triangle-exclamation me-2"></i>{{ $t('default-password.banner-title') }}</h4>
<p class="mb-0">{{ $t('default-password.banner-message') }}</p>
</div>
<RouterView />
</div>
<DefaultPasswordModal />
<footer class="page-footer mt-auto">
<div class="container mt-5">
<div class="row align-items-center">
@@ -0,0 +1,150 @@
<template>
<Teleport to="#modals">
<div v-if="visible" class="modal-backdrop fade show">
<div class="modal fade show" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable" @click.stop="">
<div class="modal-content">
<div class="modal-header bg-warning text-dark">
<h5 class="modal-title">
<i class="fa-solid fa-triangle-exclamation me-2"></i>{{ $t('default-password.modal-title') }}
</h5>
</div>
<div class="modal-body col-md-12">
<div class="alert alert-warning">
<h5 class="alert-heading">{{ $t('default-password.modal-warning-heading') }}</h5>
<p>{{ $t('default-password.modal-warning-text') }}</p>
<hr>
<p class="mb-0 fw-bold">{{ $t('default-password.modal-warning-note') }}</p>
</div>
<form @submit.prevent="updatePassword">
<div class="form-group mb-3">
<label class="form-label" for="default-oldpw">{{ $t('default-password.current-label') }}</label>
<input id="default-oldpw" v-model="pwFormData.OldPassword" class="form-control"
:class="{ 'is-invalid': pwFormData.Password && !pwFormData.OldPassword }" type="password" required>
</div>
<div class="form-group mb-3">
<label class="form-label" for="default-newpw">{{ $t('default-password.new-label') }}</label>
<input id="default-newpw" v-model="pwFormData.Password" class="form-control"
:class="{ 'is-invalid': passwordWeak || passwordSame, 'is-valid': pwFormData.Password !== '' && !passwordWeak && !passwordSame }"
type="password" required>
<div class="invalid-feedback" v-if="passwordWeak">{{ $t('default-password.weak-label') }}</div>
<div class="invalid-feedback" v-else-if="passwordSame">{{ $t('default-password.same-label') }}</div>
</div>
<div class="form-group mb-3">
<label class="form-label" for="default-confirmnewpw">{{ $t('default-password.confirm-label') }}</label>
<input id="default-confirmnewpw" v-model="pwFormData.PasswordRepeat" class="form-control"
:class="{ 'is-invalid': passwordMismatch, 'is-valid': pwFormData.PasswordRepeat !== '' && !passwordMismatch && !passwordWeak && !passwordSame }"
type="password" required>
<div class="invalid-feedback" v-if="passwordMismatch">{{ $t('default-password.mismatch-label') }}</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" :disabled="submitting || !passwordChangeAllowed" @click.prevent="updatePassword">
<i class="fa-solid fa-floppy-disk me-2"></i>{{ $t('default-password.change-button-text') }}
</button>
</div>
</div>
</div>
</div>
</div>
</Teleport>
</template>
<script setup>
import { computed, ref } from "vue";
import { authStore } from "@/stores/auth";
import { profileStore } from "@/stores/profile";
import { settingsStore } from "@/stores/settings";
import { notify } from "@kyvg/vue3-notification";
import { useI18n } from "vue-i18n";
const auth = authStore();
const profile = profileStore();
const settings = settingsStore();
const { t } = useI18n();
const visible = computed(() => auth.IsAuthenticated && auth.DefaultPasswordInUse);
const pwFormData = ref({
OldPassword: 'wgportal-default',
Password: '',
PasswordRepeat: '',
});
const submitting = ref(false);
const minPasswordLength = computed(() => settings.Setting('MinPasswordLength') || 16);
const passwordWeak = computed(() => {
return pwFormData.value.Password && pwFormData.value.Password.length > 0 && pwFormData.value.Password.length < minPasswordLength.value;
});
const passwordMismatch = computed(() => {
return pwFormData.value.PasswordRepeat !== '' && pwFormData.value.Password !== pwFormData.value.PasswordRepeat;
});
const passwordSame = computed(() => {
return pwFormData.value.OldPassword && pwFormData.value.Password && pwFormData.value.OldPassword === pwFormData.value.Password;
});
const passwordChangeAllowed = computed(() => {
return pwFormData.value.Password &&
pwFormData.value.Password.length >= minPasswordLength.value &&
!passwordMismatch.value &&
pwFormData.value.OldPassword &&
pwFormData.value.OldPassword.length > 0 &&
!passwordSame.value;
});
const updatePassword = async () => {
if (!passwordChangeAllowed.value || submitting.value) {
return;
}
submitting.value = true;
try {
await profile.changePassword(pwFormData.value);
auth.SetDefaultPasswordInUse(false);
pwFormData.value.OldPassword = '';
pwFormData.value.Password = '';
pwFormData.value.PasswordRepeat = '';
notify({
title: t('default-password.success-title'),
text: t('default-password.success-text'),
type: 'success',
duration: 5000,
});
await settings.LoadSettings();
await profile.LoadUser();
} catch (e) {
notify({
title: "Failed to update password!",
text: e.toString(),
type: 'error',
});
} finally {
submitting.value = false;
}
};
</script>
<style scoped>
.modal.show {
display: block;
opacity: 1.0;
}
.modal-backdrop {
background-color: rgba(0, 0, 0, 0.7) !important;
z-index: 1055;
}
.modal-backdrop.show {
opacity: 1.0 !important;
}
</style>
+2 -1
View File
@@ -80,7 +80,8 @@ function handleResponse(response) {
if (!response.ok) {
const auth = authStore();
if ([401, 403].includes(response.status) && auth.IsAuthenticated) {
const isDefaultPasswordError = data && data.Message && data.Message.toLowerCase().includes("default admin password");
if ([401, 403].includes(response.status) && auth.IsAuthenticated && !isDefaultPasswordError) {
console.log("unauthorized response received, redirecting to login...");
// handle unauthorized session without clearing return url
auth.HandleUnauthorized();
+8 -1
View File
@@ -8,6 +8,12 @@ let failureCount = 0;
export const websocketWrapper = {
connect() {
const auth = authStore();
if (!auth.IsAuthenticated || auth.DefaultPasswordInUse) {
this.disconnect();
return;
}
if (socket) {
console.log('WebSocket already connected, re-using existing connection.');
return;
@@ -69,7 +75,8 @@ export const websocketWrapper = {
scheduleReconnect() {
if (reconnectTimer) return;
if (!authStore().IsAuthenticated) return; // Don't reconnect if not logged in
const auth = authStore();
if (!auth.IsAuthenticated || auth.DefaultPasswordInUse) return;
reconnectTimer = setInterval(() => {
if (failureCount > 2) {
+17
View File
@@ -32,6 +32,23 @@
"button": "Anmelden",
"button-webauthn": "Passkey verwenden"
},
"default-password": {
"banner-title": "Sicherheitswarnung: Standardpasswort wird verwendet",
"banner-message": "Das Standard-Administratorpasswort ist noch in Verwendung. Solange das Passwort nicht geändert wird, sind keine weiteren Aktionen möglich.",
"modal-title": "Standard-Administratorpasswort ändern",
"modal-warning-heading": "Standardpasswort in Verwendung",
"modal-warning-text": "Das Standard-Administratorpasswort ist derzeit noch in Verwendung. Um Ihre Installation zu schützen, müssen Sie das Passwort jetzt ändern.",
"modal-warning-note": "Hinweis: Solange das Passwort nicht geändert wird, sind keine weiteren Aktionen möglich.",
"current-label": "Aktuelles Passwort",
"new-label": "Neues Passwort",
"confirm-label": "Neues Passwort bestätigen",
"weak-label": "Das Passwort ist zu kurz.",
"mismatch-label": "Passwörter stimmen nicht überein.",
"same-label": "Das neue Passwort muss sich vom aktuellen Passwort unterscheiden.",
"change-button-text": "Passwort ändern",
"success-title": "Passwort geändert!",
"success-text": "Das Passwort wurde erfolgreich geändert. Alle Aktionen sind nun freigeschaltet."
},
"peer-config-download": {
"headline": "VPN-Konfiguration wird heruntergeladen",
"in-progress": "Der Download Ihrer WireGuard-Konfiguration startet automatisch. Bitte warten...",
+17
View File
@@ -32,6 +32,23 @@
"button": "Sign in",
"button-webauthn": "Use Passkey"
},
"default-password": {
"banner-title": "Security Warning: Default Password in Use",
"banner-message": "The default administrator password is still in use. Unless the password gets changed, no further actions are possible.",
"modal-title": "Change Default Administrator Password",
"modal-warning-heading": "Default Password In Use",
"modal-warning-text": "The default administrator password is currently in use. To protect your installation from unauthorized access, you must change the password now.",
"modal-warning-note": "Note: Unless the password gets changed, no further actions are possible.",
"current-label": "Current Password",
"new-label": "New Password",
"confirm-label": "Confirm New Password",
"weak-label": "The password is too short.",
"mismatch-label": "Passwords do not match.",
"same-label": "The new password must be different from the current password.",
"change-button-text": "Change Password",
"success-title": "Password Changed!",
"success-text": "Password changed successfully. All actions are now unlocked."
},
"peer-config-download": {
"headline": "Downloading VPN Configuration",
"in-progress": "Your WireGuard configuration download will start automatically. Please wait...",
+5
View File
@@ -150,6 +150,11 @@ router.beforeEach(async (to) => {
}
}
// Keep restricted views from mounting and loading data until the password is changed.
if (auth.IsAuthenticated && auth.DefaultPasswordInUse && to.path !== '/') {
return { name: 'home', replace: true }
}
// redirect to returnUrl if already authenticated and accessing login page
if (to.path === '/login' && auth.IsAuthenticated) {
const returnUrl = auth.ReturnUrl
+22 -2
View File
@@ -17,6 +17,7 @@ export const authStore = defineStore('auth',{
fetching: false,
sessionChecked: false,
sessionPromise: null,
defaultPasswordInUse: JSON.parse(localStorage.getItem('user'))?.DefaultPasswordInUse || false,
}),
getters: {
UserIdentifier: (state) => state.user?.Identifier || 'unknown',
@@ -24,6 +25,7 @@ export const authStore = defineStore('auth',{
LoginProviders: (state) => state.providers,
IsAuthenticated: (state) => state.user != null,
IsAdmin: (state) => state.user?.IsAdmin || false,
DefaultPasswordInUse: (state) => state.defaultPasswordInUse || false,
ReturnUrl: (state) => state.returnUrl || '/',
IsWebAuthnEnabled: (state) => {
if (state.webAuthnCredentials) {
@@ -317,17 +319,32 @@ export const authStore = defineStore('auth',{
return Promise.reject(new Error("login failed"))
})
},
SetDefaultPasswordInUse(inUse) {
this.defaultPasswordInUse = inUse;
if (this.user) {
this.user.DefaultPasswordInUse = inUse;
localStorage.setItem('user', JSON.stringify(this.user));
if (inUse) {
websocketWrapper.disconnect();
} else {
websocketWrapper.connect();
}
}
},
// -- internal setters
setUserInfo(userInfo) {
// store user details and jwt in local storage to keep user logged in between page refreshes
if (userInfo && (userInfo.Identifier || userInfo.UserIdentifier)) {
const defaultPw = !!userInfo['DefaultPasswordInUse'];
this.defaultPasswordInUse = defaultPw;
if ('UserIdentifier' in userInfo && userInfo.UserIdentifier) { // session object
this.user = {
Identifier: userInfo['UserIdentifier'],
Firstname: userInfo['UserFirstname'] || '',
Lastname: userInfo['UserLastname'] || '',
Email: userInfo['UserEmail'] || '',
IsAdmin: userInfo['IsAdmin'] || false
IsAdmin: userInfo['IsAdmin'] || false,
DefaultPasswordInUse: defaultPw
}
} else if ('Identifier' in userInfo && userInfo.Identifier) { // user object
this.user = {
@@ -335,13 +352,16 @@ export const authStore = defineStore('auth',{
Firstname: userInfo['Firstname'] || '',
Lastname: userInfo['Lastname'] || '',
Email: userInfo['Email'] || '',
IsAdmin: userInfo['IsAdmin'] || false
IsAdmin: userInfo['IsAdmin'] || false,
DefaultPasswordInUse: defaultPw
}
} else {
this.user = null
this.defaultPasswordInUse = false
}
} else {
this.user = null
this.defaultPasswordInUse = false
}
if (this.user) {
+28 -10
View File
@@ -42,11 +42,20 @@ const login = async function () {
const dest = returnUrl.value && returnUrl.value !== '/login' ? returnUrl.value : (auth.ReturnUrl || '/')
auth.Login(username.value, password.value)
.then(uid => {
notify({
title: "Logged in",
text: "Authentication succeeded!",
type: 'success',
});
if (auth.DefaultPasswordInUse) {
notify({
title: "Default Password in Use!",
text: "Please change the default administrator password immediately. Unless the password gets changed, no further actions are possible.",
type: 'warn',
duration: 10000,
});
} else {
notify({
title: "Logged in",
text: "Authentication succeeded!",
type: 'success',
});
}
loggingIn.value = false;
settings.LoadSettings(); // reload full settings
auth.ResetReturnUrl();
@@ -71,11 +80,20 @@ const loginWebAuthn = async function () {
const dest = returnUrl.value && returnUrl.value !== '/login' ? returnUrl.value : (auth.ReturnUrl || '/')
auth.LoginWebAuthn()
.then(uid => {
notify({
title: "Logged in",
text: "Authentication succeeded!",
type: 'success',
});
if (auth.DefaultPasswordInUse) {
notify({
title: "Default Password in Use!",
text: "Please change the default administrator password immediately. Unless the password gets changed, no further actions are possible.",
type: 'warn',
duration: 10000,
});
} else {
notify({
title: "Logged in",
text: "Authentication succeeded!",
type: 'success',
});
}
loggingIn.value = false;
settings.LoadSettings(); // reload full settings
auth.ResetReturnUrl();
+2 -1
View File
@@ -57,6 +57,7 @@ const passwordChangeAllowed = computed(() => {
const updatePassword = async () => {
try {
await profile.changePassword(pwFormData.value);
auth.SetDefaultPasswordInUse(false);
pwFormData.value.OldPassword = '';
pwFormData.value.Password = '';
@@ -85,7 +86,7 @@ const updatePassword = async () => {
<p class="lead">{{ $t('settings.abstract') }}</p>
<div class="card border-secondary p-5 mt-5" v-if="profile.user.Source === 'db'">
<div class="card border-secondary p-5 mt-5" v-if="profile.user.AuthSources?.includes('db')">
<h2 class="display-7">{{ $t('settings.password.headline') }}</h2>
<p class="lead">{{ $t('settings.password.abstract') }}</p>
<hr class="my-4">