mirror of
https://github.com/unraid/api.git
synced 2026-01-04 15:39:52 -06:00
feat: allow csrf passing through querystring
This commit is contained in:
@@ -2,6 +2,8 @@ import { Injectable, InternalServerErrorException, Logger, OnModuleInit } from '
|
|||||||
|
|
||||||
import { Model as CasbinModel, Enforcer, newEnforcer, StringAdapter } from 'casbin';
|
import { Model as CasbinModel, Enforcer, newEnforcer, StringAdapter } from 'casbin';
|
||||||
|
|
||||||
|
import { LOG_LEVEL } from '@app/environment';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CasbinService {
|
export class CasbinService {
|
||||||
private readonly logger = new Logger(CasbinService.name);
|
private readonly logger = new Logger(CasbinService.name);
|
||||||
@@ -18,7 +20,9 @@ export class CasbinService {
|
|||||||
const casbinPolicy = new StringAdapter(policy);
|
const casbinPolicy = new StringAdapter(policy);
|
||||||
try {
|
try {
|
||||||
const enforcer = await newEnforcer(casbinModel, casbinPolicy);
|
const enforcer = await newEnforcer(casbinModel, casbinPolicy);
|
||||||
enforcer.enableLog(true);
|
if (LOG_LEVEL === 'TRACE') {
|
||||||
|
enforcer.enableLog(true);
|
||||||
|
}
|
||||||
|
|
||||||
return enforcer;
|
return enforcer;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ export class UserCookieStrategy extends PassportStrategy(Strategy, strategyName)
|
|||||||
|
|
||||||
public validate = async (req: CustomRequest): Promise<any> => {
|
public validate = async (req: CustomRequest): Promise<any> => {
|
||||||
return (
|
return (
|
||||||
this.authService.validateCsrfToken(req.headers['x-csrf-token']) &&
|
this.authService.validateCsrfToken(
|
||||||
this.authService.validateCookiesCasbin(req.cookies)
|
req.headers['x-csrf-token'] || (req.params as { csrf_token?: string })?.csrf_token
|
||||||
|
) && this.authService.validateCookiesCasbin(req.cookies)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import { useI18n } from 'vue-i18n';
|
|||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const downloadUrl = computed(() => new URL(`/graphql/api/logs`, WEBGUI_GRAPHQL));
|
const downloadUrl = computed(() => {
|
||||||
|
const url = new URL(`/graphql/api/logs`, WEBGUI_GRAPHQL);
|
||||||
|
url.searchParams.append('csrf_token', globalThis.csrf_token);
|
||||||
|
return url;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user