opnsense: sanitize usernames for creating peers

This commit is contained in:
2025-01-09 14:44:48 -08:00
parent 29fbccc953
commit 80acec720c
3 changed files with 9 additions and 7 deletions

View File

@@ -0,0 +1,3 @@
export function opnsenseSanitezedUsername(username: string) {
return username.slice(0, 63).replace(/[^a-zA-Z0-9_-]/g, '_');
}

View File

@@ -7,6 +7,7 @@ import { env } from '$env/dynamic/private';
import { and, count, eq, isNull } from 'drizzle-orm';
import { err, ok, type Result } from '$lib/types';
import type { DeviceDetails } from '$lib/devices';
import { opnsenseSanitezedUsername } from '$lib/opnsense';
export async function findDevices(userId: string) {
return db.query.devices.findMany({
@@ -196,7 +197,7 @@ async function opnsenseCreateClient(params: {
body: JSON.stringify({
configbuilder: {
enabled: '1',
name: `vpgen-${params.username}`,
name: `vpgen-${opnsenseSanitezedUsername(params.username)}`,
pubkey: params.pubkey,
psk: params.psk,
tunneladdress: params.allowedIps,