mirror of
https://github.com/tale/headplane.git
synced 2026-08-10 22:06:52 +00:00
fix: handle registration keys on headscale 0.29+
Closes HP-555.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
const authRequestKeyPattern = /^hskey-authreq-[A-Za-z0-9_-]{16,}$/;
|
||||
const authRequestKeySearchPattern = /hskey-authreq-[A-Za-z0-9_-]{16,}/;
|
||||
const legacyMachineKeyPattern = /^mkey:[A-Za-z0-9_-]{16,}$/;
|
||||
const registerUrlPattern = /\/register\/([^\s?#]+)/;
|
||||
const registrationKeySuffixPattern = /^[A-Za-z0-9_-]{24,}$/;
|
||||
|
||||
export function normalizeRegistrationKey(value: string): string | null {
|
||||
const trimmed = value.trim();
|
||||
if (trimmed.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const registerUrlMatch = trimmed.match(registerUrlPattern);
|
||||
if (registerUrlMatch) {
|
||||
const token = normalizeRegistrationToken(registerUrlMatch[1]);
|
||||
if (token) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
const authRequestKeyMatch = trimmed.match(authRequestKeySearchPattern);
|
||||
if (authRequestKeyMatch) {
|
||||
return authRequestKeyMatch[0];
|
||||
}
|
||||
|
||||
return normalizeRegistrationToken(trimmed);
|
||||
}
|
||||
|
||||
function normalizeRegistrationToken(value: string): string | null {
|
||||
let token: string;
|
||||
try {
|
||||
token = decodeURIComponent(value.trim());
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (authRequestKeyPattern.test(token) || legacyMachineKeyPattern.test(token)) {
|
||||
return token;
|
||||
}
|
||||
|
||||
if (registrationKeySuffixPattern.test(token)) {
|
||||
return `hskey-authreq-${token}`;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user