Compare commits

...
Author SHA1 Message Date
dependabot[bot] c92c50e007 build(deps): bump npm from 12.2.1 to 12.2.2 in /src/static/app
Bumps [npm](https://github.com/npm/cli) from 12.2.1 to 12.2.2.
- [Release notes](https://github.com/npm/cli/releases)
- [Changelog](https://github.com/npm/cli/blob/latest/CHANGELOG.md)
- [Commits](https://github.com/npm/cli/compare/v12.2.1...v12.2.2)

---
updated-dependencies:
- dependency-name: npm
  dependency-version: 12.2.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
2026-11-09 20:34:37 +00:00
daanselen 0a9f37cd2e fix: enforce a 2 minute wait for reset and use secrets library 2026-11-04 14:46:08 +01:00
daanselen a00799c3c5 feat: improve robustness of the installation and update process 2026-11-04 13:47:34 +01:00
7 changed files with 131 additions and 59 deletions
+1
View File
@@ -33,6 +33,7 @@ pnpm-debug.log*
lerna-debug.log*
dist
/src/static/.dist-staging.*
node_modules
.DS_Store
+5 -5
View File
@@ -113,10 +113,12 @@ def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration],
return ResponseObject(False, "Please provide a valid Email")
token = dashboardClients.GenerateClientPasswordResetToken(u.get('ClientID'))
if not token:
return ResponseObject(False, "A reset token was recently sent. Please wait 2 minutes before requesting another.")
status, msg = emailSender.send(
email, "[WGDashboard | Client] Reset Password",
f"Hi {email}, \n\nIt looks like you're trying to reset your password at {date} \n\nEnter this 6 digits code on the Forgot Password to continue:\n\n{token}\n\nThis code will expire in 30 minutes for your security. If you didn’t request a password reset, you can safely ignore this email—your current password will remain unchanged.\n\nIf you need help, feel free to contact support.\n\nBest regards,\n\nWGDashboard"
f"Hi {email}, \n\nIt looks like you're trying to reset your password at {date} \n\nEnter this reset token on the Forgot Password page to continue:\n\n{token}\n\nThis token will expire in 30 minutes for your security. If you didn’t request a password reset, you can safely ignore this email—your current password will remain unchanged.\n\nIf you need help, feel free to contact support.\n\nBest regards,\n\nWGDashboard"
)
return ResponseObject(status, msg)
@@ -150,11 +152,9 @@ def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration],
return ResponseObject(False, "Please provide a valid Email")
if not dashboardClients.ValidateClientPasswordResetToken(u.get('ClientID'), token):
return ResponseObject(False, "Verification code is either invalid or expired")
return ResponseObject(False, "Reset token is either invalid or expired")
status, msg = dashboardClients.ResetClientPassword(u.get('ClientID'), password, confirmPassword)
dashboardClients.RevokeClientPasswordResetToken(u.get('ClientID'), token)
status, msg = dashboardClients.ResetClientPassword(u.get('ClientID'), password, confirmPassword, token)
return ResponseObject(status, msg)
+50 -13
View File
@@ -1,6 +1,6 @@
import datetime
import hashlib
import random
import secrets
import uuid
import bcrypt
@@ -305,7 +305,9 @@ class DashboardClients:
def GetClientAssignedPeers(self, ClientID):
return self.DashboardClientsPeerAssignment.GetAssignedPeers(ClientID)
def ResetClientPassword(self, ClientID, NewPassword, ConfirmNewPassword) -> tuple[bool, str] | tuple[bool, None]:
def ResetClientPassword(
self, ClientID, NewPassword, ConfirmNewPassword, ResetToken
) -> tuple[bool, str] | tuple[bool, None]:
c = self.GetClient(ClientID)
if c is None:
return False, "Client does not exist"
@@ -316,18 +318,36 @@ class DashboardClients:
pwStrength, msg = ValidatePasswordStrength(NewPassword)
if not pwStrength:
return pwStrength, msg
if not isinstance(ResetToken, str) or not ResetToken or len(ResetToken) > 128:
return False, "Reset token is either invalid or expired"
tokenDigest = hashlib.sha256(ResetToken.encode("utf-8")).hexdigest()
now = datetime.datetime.now()
try:
with self.engine.begin() as conn:
tokenClaimed = conn.execute(
self.dashboardClientsPasswordResetLinkTable.update().values({
"ExpiryDate": now
}).where(
db.and_(
self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == tokenDigest,
self.dashboardClientsPasswordResetLinkTable.c.ExpiryDate > now
)
)
)
if tokenClaimed.rowcount != 1:
return False, "Reset token is either invalid or expired"
conn.execute(
self.dashboardClientsTable.update().values({
"TotpKeyVerified": None,
"TotpKey": pyotp.random_base32(),
"Password": bcrypt.hashpw(NewPassword.encode('utf-8'), bcrypt.gensalt()).decode("utf-8"),
}).where(
self.dashboardClientsTable.c.ClientID == ClientID
)
)
self.logger.log(Message=f"User {ClientID} reset password and TOTP")
self.logger.log(Message=f"User {ClientID} reset password")
except Exception as e:
self.logger.log(Status="false", Message=f"User {ClientID} reset password failed, reason: {str(e)}")
return False, "Reset password failed."
@@ -420,11 +440,24 @@ class DashboardClients:
if c is None:
return False
newToken = str(random.randint(0, 999999)).zfill(6)
newToken = secrets.token_urlsafe(32)
tokenDigest = hashlib.sha256(newToken.encode("utf-8")).hexdigest()
now = datetime.datetime.now()
with self.engine.begin() as conn:
recentToken = conn.execute(
self.dashboardClientsPasswordResetLinkTable.select().where(
db.and_(
self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
self.dashboardClientsPasswordResetLinkTable.c.CreatedDate > now - datetime.timedelta(minutes=2)
)
).limit(1)
).first()
if recentToken:
return False
conn.execute(
self.dashboardClientsPasswordResetLinkTable.update().values({
"ExpiryDate": datetime.datetime.now()
"ExpiryDate": now
}).where(
db.and_(
@@ -435,10 +468,10 @@ class DashboardClients:
)
conn.execute(
self.dashboardClientsPasswordResetLinkTable.insert().values({
"ResetToken": newToken,
"ResetToken": tokenDigest,
"ClientID": ClientID,
"CreatedDate": datetime.datetime.now(),
"ExpiryDate": datetime.datetime.now() + datetime.timedelta(minutes=30)
"CreatedDate": now,
"ExpiryDate": now + datetime.timedelta(minutes=30)
})
)
@@ -446,13 +479,14 @@ class DashboardClients:
def ValidateClientPasswordResetToken(self, ClientID, Token):
c = self.GetClient(ClientID)
if c is None:
if c is None or not isinstance(Token, str) or not Token or len(Token) > 128:
return False
tokenDigest = hashlib.sha256(Token.encode("utf-8")).hexdigest()
with self.engine.connect() as conn:
t = conn.execute(
self.dashboardClientsPasswordResetLinkTable.select().where(
db.and_(self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token,
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == tokenDigest,
self.dashboardClientsPasswordResetLinkTable.c.ExpiryDate > datetime.datetime.now())
)
@@ -460,13 +494,16 @@ class DashboardClients:
return t is not None
def RevokeClientPasswordResetToken(self, ClientID, Token):
if not isinstance(Token, str) or len(Token) > 128:
return False
tokenDigest = hashlib.sha256(Token.encode("utf-8")).hexdigest()
with self.engine.begin() as conn:
conn.execute(
self.dashboardClientsPasswordResetLinkTable.update().values({
"ExpiryDate": datetime.datetime.now()
}).where(
db.and_(self.dashboardClientsPasswordResetLinkTable.c.ClientID == ClientID,
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == Token)
self.dashboardClientsPasswordResetLinkTable.c.ResetToken == tokenDigest)
)
)
return True
+16 -16
View File
@@ -23,7 +23,7 @@
"fuse.js": "^7.5.0",
"i": "^0.3.7",
"is-cidr": "^7.0.3",
"npm": "^12.2.1",
"npm": "^12.2.2",
"ol": "^10.11.0",
"pinia": "^4.1.0",
"pinia-plugin-persistedstate": "^4.7.1",
@@ -4318,9 +4318,9 @@
"license": "MIT"
},
"node_modules/npm": {
"version": "12.2.1",
"resolved": "https://registry.npmjs.org/npm/-/npm-12.2.1.tgz",
"integrity": "sha512-bKCmFRVT/BB+YPEYbZwQ1XUI3N5t4xKSpU1MxOjo7z3iWzKBJ0ZXRC1xFdEN+TC7N5TdywaBzf2dMXGJq/e2PQ==",
"version": "12.2.2",
"resolved": "https://registry.npmjs.org/npm/-/npm-12.2.2.tgz",
"integrity": "sha512-KglgbZyacf7jH+FHuNRqVuCzQi8VhI2a7J87Ix43FsPTuZoGWmIXXGdZtBUOA79vwL+IJREqURVzupA7PsQTcA==",
"bundleDependencies": [
"@isaacs/string-locale-compare",
"@npmcli/arborist",
@@ -4408,13 +4408,13 @@
"@npmcli/map-workspaces": "^6.0.0",
"@npmcli/metavuln-calculator": "^10.0.0",
"@npmcli/package-json": "^8.0.0",
"@npmcli/promise-spawn": "^10.0.0",
"@npmcli/promise-spawn": "^10.0.1",
"@npmcli/redact": "^5.0.0",
"@npmcli/run-script": "^11.0.0",
"@sigstore/tuf": "^5.0.0",
"abbrev": "^5.0.0",
"archy": "~1.0.0",
"bin-links": "^7.0.0",
"bin-links": "^7.0.1",
"cacache": "^21.0.1",
"chalk": "^5.6.2",
"ci-info": "^4.4.0",
@@ -4430,7 +4430,7 @@
"json-parse-even-better-errors": "^6.0.0",
"libnpmaccess": "^11.0.0",
"libnpmdiff": "^9.0.4",
"libnpmexec": "^11.0.4",
"libnpmexec": "^11.0.5",
"libnpmfund": "^8.0.4",
"libnpmorg": "^9.0.0",
"libnpmpack": "^10.0.4",
@@ -4453,12 +4453,12 @@
"npm-registry-fetch": "^20.0.1",
"npm-user-validate": "^5.0.0",
"p-map": "^7.0.4",
"pacote": "^22.0.0",
"pacote": "^22.0.1",
"parse-conflict-json": "^6.0.0",
"proc-log": "^7.0.0",
"qrcode-terminal": "^0.12.0",
"read": "^6.0.0",
"semver": "^7.8.5",
"semver": "^7.8.6",
"spdx-expression-parse": "^4.0.0",
"ssri": "^14.0.0",
"supports-color": "^10.2.2",
@@ -4743,7 +4743,7 @@
}
},
"node_modules/npm/node_modules/@npmcli/promise-spawn": {
"version": "10.0.0",
"version": "10.0.1",
"inBundle": true,
"license": "ISC",
"dependencies": {
@@ -4902,7 +4902,7 @@
}
},
"node_modules/npm/node_modules/bin-links": {
"version": "7.0.0",
"version": "7.0.1",
"inBundle": true,
"license": "ISC",
"dependencies": {
@@ -5176,7 +5176,7 @@
}
},
"node_modules/npm/node_modules/ip-address": {
"version": "10.7.2",
"version": "10.7.5",
"inBundle": true,
"license": "MIT",
"engines": {
@@ -5267,7 +5267,7 @@
}
},
"node_modules/npm/node_modules/libnpmexec": {
"version": "11.0.4",
"version": "11.0.5",
"inBundle": true,
"license": "ISC",
"dependencies": {
@@ -5707,7 +5707,7 @@
}
},
"node_modules/npm/node_modules/pacote": {
"version": "22.0.0",
"version": "22.0.1",
"inBundle": true,
"license": "ISC",
"dependencies": {
@@ -5860,7 +5860,7 @@
"optional": true
},
"node_modules/npm/node_modules/semver": {
"version": "7.8.5",
"version": "7.8.6",
"inBundle": true,
"license": "ISC",
"bin": {
@@ -6070,7 +6070,7 @@
}
},
"node_modules/npm/node_modules/undici": {
"version": "6.29.0",
"version": "6.29.1",
"inBundle": true,
"license": "MIT",
"engines": {
+1 -1
View File
@@ -27,7 +27,7 @@
"fuse.js": "^7.5.0",
"i": "^0.3.7",
"is-cidr": "^7.0.3",
"npm": "^12.2.1",
"npm": "^12.2.2",
"ol": "^10.11.0",
"pinia": "^4.1.0",
"pinia-plugin-persistedstate": "^4.7.1",
+13 -15
View File
@@ -29,12 +29,8 @@ const requestToken = async (e) => {
}
const code = ref("")
const parseCode = () => {
code.value = code.value.replace(/\D/i, "")
code.value = code.value.slice(0, 6)
}
const codeReady = computed(() => {
return /^[0-9]{6}$/.test(code.value)
return code.value.trim().length > 0
})
const codeValidated = ref(false)
const validateCode = async (e) => {
@@ -42,13 +38,13 @@ const validateCode = async (e) => {
loading.value = true
let codeValidation = await axiosPost("/api/resetPassword/validateResetToken", {
Email: email.value,
Token: code.value
Token: code.value.trim()
})
loading.value = false
if (codeValidation.status){
codeValidated.value = true
}else{
store.newNotification("Your verification code is either invalid or expired", "danger")
store.newNotification("Your reset token is either invalid or expired", "danger")
}
}
@@ -63,7 +59,7 @@ const resetPassword = async (e) => {
loading.value = true;
let reset = await axiosPost("/api/resetPassword", {
Email: email.value,
Token: code.value,
Token: code.value.trim(),
Password: password.value,
ConfirmPassword: confirmPassword.value
})
@@ -71,6 +67,8 @@ const resetPassword = async (e) => {
store.newNotification("Password reset! Now you can sign in with your new password", "success")
await router.push('/signin')
}else{
store.newNotification(reset.message || "Password reset failed", "danger")
}
}
</script>
@@ -98,7 +96,7 @@ const resetPassword = async (e) => {
autocomplete="email"
autofocus
class="form-control rounded-3 border-0" id="email" placeholder="email">
<label for="email" class="d-flex">
<label for="token" class="d-flex">
<i class="bi bi-person-circle me-2"></i>
Email
</label>
@@ -122,7 +120,7 @@ const resetPassword = async (e) => {
</a>
<div class="text-center">
<h1 class="display-4">Almost there</h1>
<p class="text-muted">Enter the code you received below to retrieve a reset your password</p>
<p class="text-muted">Enter the reset token you received below to reset your password</p>
<p class="text-muted" v-if="resendCountdown > 0">Didn't get the code? Maybe check your Spam/Junk mailbox. You can get another code in {{ resendCountdown }} seconds.</p>
<a role="button"
:class="{disabled: loading}"
@@ -131,17 +129,17 @@ const resetPassword = async (e) => {
<form class="mt-4 d-flex flex-column gap-3" @submit="e => validateCode(e)">
<div class="form-floating">
<input type="text"
inputmode="numeric"
required
:disabled="loading"
v-model="code"
@keyup="parseCode()"
autocomplete="one-time-code"
autocomplete="off"
autocapitalize="off"
spellcheck="false"
autofocus
class="form-control rounded-3 border-0" id="token" placeholder="token">
<label for="email" class="d-flex">
<label for="token" class="d-flex">
<i class="bi bi-person-circle me-2"></i>
6 Digits Verification Code
Password Reset Token
</label>
</div>
<button
+45 -9
View File
@@ -393,12 +393,12 @@ _checkNode(){
then
printf "[WGDashboard] %s Node.js and npm are still not installed, halting script now.\n" "$heavy_crossmark"
printf "%s\n" "$helpMsg"
kill $TOP_PID
return 1
elif ! _isNodeVersionSupported
then
printf "[WGDashboard] %s Found Node.js %s, but the frontend requires Node.js 20.19+ or 22.12+. Halting install now.\n" "$heavy_crossmark" "$(node --version)"
printf "%s\n" "$helpMsg"
kill $TOP_PID
return 1
else
printf "[WGDashboard] %s Node.js %s and npm %s are installed\n" "$heavy_checkmark" "$(node --version)" "$(npm --version)"
fi
@@ -406,19 +406,50 @@ _checkNode(){
_compileFrontend(){
_logSection "Compiling Frontend"
_checkNode
if ! _checkNode; then
return 1
fi
local dir
for dir in "${frontend_dirs[@]}"; do
local staging_root live_dir backup_dir dir output_dir index
local frontend_output_dirs=("WGDashboardAdmin" "WGDashboardClient")
staging_root=$(mktemp -d "$PWD/static/.dist-staging.XXXXXX") || return 1
live_dir="$PWD/static/dist"
backup_dir="${staging_root}.previous"
for index in "${!frontend_dirs[@]}"; do
dir="${frontend_dirs[$index]}"
output_dir="$staging_root/${frontend_output_dirs[$index]}"
printf "[WGDashboard] %s Compiling frontend in %s\n" "$install" "$dir"
if ! ( cd "$dir" && npm ci && npm run build ) &>> ./log/install.txt
if ! ( cd "$dir" && npm ci && npm run build -- --outDir "$output_dir" --emptyOutDir ) &>> ./log/install.txt
then
printf "[WGDashboard] %s Failed to compile frontend in %s, halting script now.\n" "$heavy_crossmark" "$dir"
printf "%s\n" "$helpMsg"
kill $TOP_PID
rm -rf "$staging_root"
return 1
fi
done
if [[ ! -f "$staging_root/WGDashboardAdmin/index.html" || ! -f "$staging_root/WGDashboardClient/client.html" ]]; then
printf "[WGDashboard] %s Frontend build did not produce the expected entry files.\n" "$heavy_crossmark"
rm -rf "$staging_root"
return 1
fi
if [[ -e "$live_dir" ]] && ! mv "$live_dir" "$backup_dir"; then
printf "[WGDashboard] %s Could not preserve the current frontend bundle.\n" "$heavy_crossmark"
rm -rf "$staging_root"
return 1
fi
if ! mv "$staging_root" "$live_dir"; then
printf "[WGDashboard] %s Could not install the new frontend bundle.\n" "$heavy_crossmark"
if [[ -e "$backup_dir" ]]; then
mv "$backup_dir" "$live_dir"
fi
rm -rf "$staging_root"
return 1
fi
rm -rf "$backup_dir"
printf "[WGDashboard] %s Frontend is compiled\n" "$heavy_checkmark"
}
@@ -456,7 +487,9 @@ install_wgd(){
_installPythonVenv
_installPythonPip
_checkWireguard
_compileFrontend
if ! _compileFrontend; then
return 1
fi
sudo chmod -R 755 /etc/wireguard/
_check_and_set_venv
@@ -601,7 +634,10 @@ update_wgd() {
printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver"
{ date; git stash; git pull https://github.com/WGDashboard/WGDashboard.git $new_ver --force; } >> ./log/update.txt
chmod +x ./wgd.sh
sudo ./wgd.sh install
if ! sudo ./wgd.sh install; then
printf "[WGDashboard] %s Update installation failed. Check ./log/install.txt; the previous frontend bundle was preserved when possible.\n" "$heavy_crossmark"
return 1
fi
printf "[WGDashboard] Update completed!\n"
rm wgd.sh.old
else