Skip to content

Commit

Permalink
fix security page not properly prompting privileged session, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Dec 9, 2023
1 parent 767628a commit a65cd19
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions frontend/src/composables/useValidationHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ErrorObject, useVuelidate, type ValidationRule } from "@vuelidate/core";
import { computed } from "vue";
import type { ComputedRef, type Ref } from "vue";
import type { ComputedRef, Ref } from "vue";
import * as validators from "@vuelidate/validators";
import { createI18nMessage, helpers, type ValidatorWrapper } from "@vuelidate/validators";
import { difference, isEmpty, uniq } from "lodash-es";
Expand Down Expand Up @@ -108,7 +108,13 @@ export const validPageName = withOverrideMessage((body: ComputedRef<{ projectId:
await useInternalApi("pages/checkName", "get", body.value);
return { $valid: true };
} catch (e: AxiosError | any) {
return e?.response?.data?.detail ? { $valid: false, $message: e.response.data.detail } : { $valid: false };
if (e?.response?.data?.detail) {
return { $valid: false, $message: e.response.data.detail };
} else if (e?.response?.data?.message) {
return { $valid: false, $message: e.response.data.message };
} else {
return { $valid: false };
}
}
}, body)
)
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/pages/auth/settings/security.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function addAuthenticator() {
codes.value = e.response.data.body;
backupCodeModal.value.isOpen = true;
savedRequest.value = e.config;
} else if (e.response?.data?.detail === "error.privileged") {
} else if (e.response?.data?.message === "error.privileged") {
await router.push(useAuth.loginUrl(route.path) + "&privileged=true");
} else if (e?.toString()?.startsWith("NotAllowedError")) {
notification.error("Security Key Authentication failed!");
Expand All @@ -70,7 +70,7 @@ async function unregisterAuthenticator(authenticator: AuthSettings["authenticato
await useInternalApi("auth/webauthn/unregister", "POST", authenticator.id, { headers: { "content-type": "text/plain" } });
emit("refreshSettings");
} catch (e) {
if (e.response?.data?.detail === "error.privileged") {
if (e.response?.data?.message === "error.privileged") {
await router.push(useAuth.loginUrl(route.path) + "&privileged=true");
} else if (e?.toString()?.startsWith("NotAllowedError")) {
notification.error("Security Key Authentication failed!");
Expand All @@ -88,7 +88,7 @@ async function setupTotp() {
try {
totpData.value = await useInternalApi<{ secret: string; qrCode: string }>("auth/totp/setup", "POST");
} catch (e) {
if (e.response?.data?.detail === "error.privileged") {
if (e.response?.data?.message === "error.privileged") {
await router.push(useAuth.loginUrl(route.path) + "&privileged=true");
} else {
notification.fromError(i18n, e);
Expand All @@ -111,7 +111,7 @@ async function addTotp() {
backupCodeModal.value.isOpen = true;
savedRequest.value = e.config;
otp.value = e.response.headers["x-hangar-verify"];
} else if (e.response?.data?.detail === "error.privileged") {
} else if (e.response?.data?.message === "error.privileged") {
await router.push(useAuth.loginUrl(route.path) + "&privileged=true");
} else {
notification.fromError(i18n, e);
Expand All @@ -126,7 +126,7 @@ async function unlinkTotp() {
await useInternalApi("auth/totp/remove", "POST");
emit("refreshSettings");
} catch (e) {
if (e.response?.data?.detail === "error.privileged") {
if (e.response?.data?.message === "error.privileged") {
await router.push(useAuth.loginUrl(route.path) + "&privileged=true");
} else {
notification.fromError(i18n, e);
Expand Down Expand Up @@ -184,7 +184,7 @@ async function revealCodes() {
}
showCodes.value = true;
} catch (e) {
if (e.response?.data?.detail === "error.privileged") {
if (e.response?.data?.message === "error.privileged") {
await router.push(useAuth.loginUrl(route.path) + "&privileged=true");
} else {
notification.fromError(i18n, e);
Expand All @@ -200,7 +200,7 @@ async function generateNewCodes() {
notification.success("Regenerated backup codes!");
emit("refreshSettings");
} catch (e) {
if (e.response?.data?.detail === "error.privileged") {
if (e.response?.data?.message === "error.privileged") {
await router.push(useAuth.loginUrl(route.path) + "&privileged=true");
} else {
notification.fromError(i18n, e);
Expand Down

0 comments on commit a65cd19

Please sign in to comment.