mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
security advisory fixes opened by kolega-ai-dev
This commit is contained in:
parent
e5f794c329
commit
8f55ed9da9
7 changed files with 36 additions and 13 deletions
|
|
@ -10,6 +10,7 @@ import {
|
||||||
TextField,
|
TextField,
|
||||||
} from '@umami/react-zen';
|
} from '@umami/react-zen';
|
||||||
import { useMessages, useUpdateQuery } from '@/components/hooks';
|
import { useMessages, useUpdateQuery } from '@/components/hooks';
|
||||||
|
import { messages } from '@/components/messages';
|
||||||
import { ROLES } from '@/lib/constants';
|
import { ROLES } from '@/lib/constants';
|
||||||
|
|
||||||
export function UserAddForm({ onSave, onClose }) {
|
export function UserAddForm({ onSave, onClose }) {
|
||||||
|
|
@ -37,7 +38,10 @@ export function UserAddForm({ onSave, onClose }) {
|
||||||
<FormField
|
<FormField
|
||||||
label={formatMessage(labels.password)}
|
label={formatMessage(labels.password)}
|
||||||
name="password"
|
name="password"
|
||||||
rules={{ required: formatMessage(labels.required) }}
|
rules={{
|
||||||
|
required: formatMessage(labels.required),
|
||||||
|
minLength: { value: 8, message: formatMessage(messages.minPasswordLength, { n: '8' }) },
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<PasswordField autoComplete="new-password" data-test="input-password" />
|
<PasswordField autoComplete="new-password" data-test="input-password" />
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
import redis from '@/lib/redis';
|
import redis from '@/lib/redis';
|
||||||
|
import { parseRequest } from '@/lib/request';
|
||||||
import { ok } from '@/lib/response';
|
import { ok } from '@/lib/response';
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
|
const { error } = await parseRequest(request);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return error();
|
||||||
|
}
|
||||||
|
|
||||||
if (redis.enabled) {
|
if (redis.enabled) {
|
||||||
const token = request.headers.get('authorization')?.split(' ')?.[1];
|
const token = request.headers.get('authorization')?.split(' ')?.[1];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { saveAuth } from '@/lib/auth';
|
import { saveAuth } from '@/lib/auth';
|
||||||
import redis from '@/lib/redis';
|
import redis from '@/lib/redis';
|
||||||
import { parseRequest } from '@/lib/request';
|
import { parseRequest } from '@/lib/request';
|
||||||
import { json } from '@/lib/response';
|
import { json, serverError } from '@/lib/response';
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
const { auth, error } = await parseRequest(request);
|
const { auth, error } = await parseRequest(request);
|
||||||
|
|
@ -10,9 +10,13 @@ export async function POST(request: Request) {
|
||||||
return error();
|
return error();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redis.enabled) {
|
if (!redis.enabled) {
|
||||||
|
return serverError({
|
||||||
|
message: 'Redis is disabled',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const token = await saveAuth({ userId: auth.user.id }, 86400);
|
const token = await saveAuth({ userId: auth.user.id }, 86400);
|
||||||
|
|
||||||
return json({ user: auth.user, token });
|
return json({ user: auth.user, token });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { hashPassword } from '@/lib/password';
|
import { hashPassword } from '@/lib/password';
|
||||||
import { parseRequest } from '@/lib/request';
|
import { parseRequest } from '@/lib/request';
|
||||||
import { badRequest, json, ok, unauthorized } from '@/lib/response';
|
import { badRequest, json, notFound, ok, unauthorized } from '@/lib/response';
|
||||||
import { userRoleParam } from '@/lib/schema';
|
import { userRoleParam } from '@/lib/schema';
|
||||||
import { canDeleteUser, canUpdateUser, canViewUser } from '@/permissions';
|
import { canDeleteUser, canUpdateUser, canViewUser } from '@/permissions';
|
||||||
import { deleteUser, getUser, getUserByUsername, updateUser } from '@/queries/prisma';
|
import { deleteUser, getUser, getUserByUsername, updateUser } from '@/queries/prisma';
|
||||||
|
|
@ -27,7 +27,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
|
||||||
export async function POST(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
export async function POST(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
username: z.string().max(255).optional(),
|
username: z.string().max(255).optional(),
|
||||||
password: z.string().max(255).optional(),
|
password: z.string().min(8).max(255).optional(),
|
||||||
role: userRoleParam.optional(),
|
role: userRoleParam.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -47,6 +47,10 @@ export async function POST(request: Request, { params }: { params: Promise<{ use
|
||||||
|
|
||||||
const user = await getUser(userId);
|
const user = await getUser(userId);
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return notFound();
|
||||||
|
}
|
||||||
|
|
||||||
const data: any = {};
|
const data: any = {};
|
||||||
|
|
||||||
if (password) {
|
if (password) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { uuid } from '@/lib/crypto';
|
||||||
import { hashPassword } from '@/lib/password';
|
import { hashPassword } from '@/lib/password';
|
||||||
import { parseRequest } from '@/lib/request';
|
import { parseRequest } from '@/lib/request';
|
||||||
import { badRequest, json, unauthorized } from '@/lib/response';
|
import { badRequest, json, unauthorized } from '@/lib/response';
|
||||||
|
import { userRoleParam } from '@/lib/schema';
|
||||||
import { canCreateUser } from '@/permissions';
|
import { canCreateUser } from '@/permissions';
|
||||||
import { createUser, getUserByUsername } from '@/queries/prisma';
|
import { createUser, getUserByUsername } from '@/queries/prisma';
|
||||||
|
|
||||||
|
|
@ -11,8 +12,8 @@ export async function POST(request: Request) {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
id: z.uuid().optional(),
|
id: z.uuid().optional(),
|
||||||
username: z.string().max(255),
|
username: z.string().max(255),
|
||||||
password: z.string(),
|
password: z.string().min(8).max(255),
|
||||||
role: z.string().regex(/admin|user|view-only/i),
|
role: userRoleParam,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { auth, body, error } = await parseRequest(request, schema);
|
const { auth, body, error } = await parseRequest(request, schema);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import { ROLE_PERMISSIONS, ROLES, SHARE_TOKEN_HEADER } from '@/lib/constants';
|
import { ROLE_PERMISSIONS, ROLES, SHARE_TOKEN_HEADER } from '@/lib/constants';
|
||||||
import { secret } from '@/lib/crypto';
|
import { createAuthKey, secret } from '@/lib/crypto';
|
||||||
import { getRandomChars } from '@/lib/generate';
|
|
||||||
import { createSecureToken, parseSecureToken, parseToken } from '@/lib/jwt';
|
import { createSecureToken, parseSecureToken, parseToken } from '@/lib/jwt';
|
||||||
import redis from '@/lib/redis';
|
import redis from '@/lib/redis';
|
||||||
import { ensureArray } from '@/lib/utils';
|
import { ensureArray } from '@/lib/utils';
|
||||||
|
|
@ -53,7 +52,7 @@ export async function checkAuth(request: Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveAuth(data: any, expire = 0) {
|
export async function saveAuth(data: any, expire = 0) {
|
||||||
const authKey = `auth:${getRandomChars(32)}`;
|
const authKey = `auth:${createAuthKey()}`;
|
||||||
|
|
||||||
if (redis.enabled) {
|
if (redis.enabled) {
|
||||||
await redis.client.set(authKey, data);
|
await redis.client.set(authKey, data);
|
||||||
|
|
|
||||||
|
|
@ -63,3 +63,7 @@ export function uuid(...args: any) {
|
||||||
|
|
||||||
return process.env.USE_UUIDV7 ? v7() : v4();
|
return process.env.USE_UUIDV7 ? v7() : v4();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createAuthKey() {
|
||||||
|
return crypto.randomBytes(16).toString('hex');
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue