Skip to content

Commit

Permalink
Fixed sessions vulnerability, some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
isKONSTANTIN committed Jul 28, 2024
1 parent e4c3f9f commit c05e382
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
43 changes: 27 additions & 16 deletions components/modal/user/sessions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@
<table class="table table-xs mt-4">
<thead>
<tr>
<th>Created</th>
<th>Expires</th>
<th>Token</th>
<th>Description</th>
<th class="text-right">Action</th>
<th></th>
<th>{{ $t('modals.sessions.table.created') }}</th>
<th>{{ $t('modals.sessions.table.expires') }}</th>
<th>{{ $t('modals.sessions.table.meta') }}</th>
<th>{{ $t('modals.sessions.table.description') }}</th>
<th class="text-right">{{ $t('modals.sessions.table.action') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="session in sessions">
<tr v-for="session in sessionsData.sessions" :class="{'bg-base-200' : session.sessionId === sessionsData.currentId}">
<td class="w-36">{{ new Date(session.createdAt).toLocaleString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}) }}</td>
<td class="w-36">{{ new Date(session.expiresAt).toLocaleString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}) }}</td>
<td><p class="w-24 sm:w-56 overflow-hidden overflow-ellipsis"> {{ session.token }} </p></td>
<td><p>{{ session.description }}</p></td>
<td class="text-right">
<buttons-copy-button @click="copyToClipboard(session.token)" class="btn btn-ghost btn-xs"/>
<td>
<div class="flex gap-2 w-fit">
<div class="badge badge-primary badge-outline" v-if="session.sessionId === sessionsData.currentId">
{{ $t('modals.sessions.badges.current') }}
</div>
<div class="badge badge-warning badge-outline" v-if="session.limited">
{{ $t('modals.sessions.badges.limited') }}
</div>
</div>
</td>
<td><p>{{ session.description }}</p></td>
<td class="text-right w-1 p-1">
<buttons-delete-button @click="deleteSession(session)" v-if="session.token !== currentSessionToken" class="btn btn-ghost btn-xs"/>
<buttons-delete-button @click="deleteSession(session)" class="btn btn-ghost btn-xs"/>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -68,19 +73,18 @@ const props = defineProps({
const { t, locale } = useI18n();
const {$serverConfigs, $auth, $sessionsApi, $toastsManager } = useNuxtApp();
const {$serverConfigs, $sessionsApi, $auth, $toastsManager } = useNuxtApp();
const configs = $serverConfigs.configs.users;
const emit = defineEmits(['close'])
const sessions = ref([]);
const currentSessionToken = $auth.state().token;
const sessionsData = ref([]);
const newSessionDescription = ref();
const fetchSessions = async () => {
sessions.value = await $sessionsApi.getSessions();
sessionsData.value = await $sessionsApi.getSessions();
}
watch(() => props.opened, async () => {
Expand All @@ -95,6 +99,7 @@ const close = () => {
const newSession = () => {
$sessionsApi.newSession(configs.userSessionsLifetimeDays, newSessionDescription.value.length > 0 ? newSessionDescription.value : null).then((s) => {
if (s) {
copyToClipboard(s);
$toastsManager.pushToast(t("modals.sessions.messages.successCreate"), 2500, "success");
fetchSessions();
}else {
Expand All @@ -105,6 +110,12 @@ const newSession = () => {
const deleteSession = (session) => {
$sessionsApi.deleteSession(session.sessionId).then((s) => {
if (s && session.sessionId === sessionsData.value.currentId) {
$auth.logout(true);
return;
}
if (s) {
$toastsManager.pushToast(t("modals.sessions.messages.successDelete"), 2500, "success");
fetchSessions();
Expand Down
11 changes: 11 additions & 0 deletions lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,17 @@
"placeholders": {
"description": "Description"
},
"table": {
"created": "Created",
"expires": "Expires",
"meta": "Meta",
"description": "Description",
"action": "Action"
},
"badges": {
"current": "Current",
"limited": "Limited"
},
"messages": {
"successCreate": "Session created",
"errorCreate": "Oops, failed to create session",
Expand Down
12 changes: 12 additions & 0 deletions lang/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,18 @@
"placeholders": {
"description": "Описание"
},
"table": {
"created": "Создан",
"expires": "Истекает",
"meta": "Мета",
"description": "Описание",
"action": "Действие"
},
"badges": {
"current": "Текущий",
"limited": "Ограниченный"
},

"messages": {
"successCreate": "Сеанс создан",
"errorCreate": "Ошибка создания сеанса",
Expand Down
2 changes: 1 addition & 1 deletion libs/api/sessions/SessionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SessionsApi extends AbstractApi {
return false;
}

return data.value?.sessions;
return data.value;
}

public async newSession(lifetimeDays: number, description: string | null): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "finwave",
"version": "0.15.0",
"version": "0.16.0",
"private": true,
"scripts": {
"build": "nuxt build",
Expand Down

0 comments on commit c05e382

Please sign in to comment.