mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 10:19:51 -06:00
chore: removes formbricks_encryption_key-environment-variable (#5426)
This commit is contained in:
@@ -13,7 +13,6 @@ vi.mock("@formbricks/lib/crypto", () => ({
|
||||
// Mock constants
|
||||
vi.mock("@formbricks/lib/constants", () => ({
|
||||
ENCRYPTION_KEY: "test-encryption-key",
|
||||
FORMBRICKS_ENCRYPTION_KEY: "test-formbricks-encryption-key",
|
||||
}));
|
||||
|
||||
// Mock cuid2
|
||||
@@ -81,7 +80,6 @@ describe("generateSurveySingleUseId", () => {
|
||||
// Temporarily mock ENCRYPTION_KEY as undefined
|
||||
vi.doMock("@formbricks/lib/constants", () => ({
|
||||
ENCRYPTION_KEY: undefined,
|
||||
FORMBRICKS_ENCRYPTION_KEY: "test-formbricks-encryption-key",
|
||||
}));
|
||||
|
||||
// Re-import to get the new mock values
|
||||
@@ -94,7 +92,6 @@ describe("generateSurveySingleUseId", () => {
|
||||
// Temporarily mock ENCRYPTION_KEY as undefined
|
||||
vi.doMock("@formbricks/lib/constants", () => ({
|
||||
ENCRYPTION_KEY: undefined,
|
||||
FORMBRICKS_ENCRYPTION_KEY: "test-formbricks-encryption-key",
|
||||
}));
|
||||
|
||||
// Re-import to get the new mock values
|
||||
@@ -102,19 +99,4 @@ describe("generateSurveySingleUseId", () => {
|
||||
|
||||
expect(() => validateSurveySingleUseIdNoKey(mockEncryptedCuid)).toThrow("ENCRYPTION_KEY is not set");
|
||||
});
|
||||
|
||||
test("throws error when FORMBRICKS_ENCRYPTION_KEY is not set in validateSurveySingleUseId for AES128", async () => {
|
||||
// Temporarily mock FORMBRICKS_ENCRYPTION_KEY as undefined
|
||||
vi.doMock("@formbricks/lib/constants", () => ({
|
||||
ENCRYPTION_KEY: "test-encryption-key",
|
||||
FORMBRICKS_ENCRYPTION_KEY: undefined,
|
||||
}));
|
||||
|
||||
// Re-import to get the new mock values
|
||||
const { validateSurveySingleUseId: validateSurveySingleUseIdNoKey } = await import("./singleUseSurveys");
|
||||
|
||||
expect(() =>
|
||||
validateSurveySingleUseIdNoKey("M(.Bob=dS1!wUSH2lb,E7hxO=He1cnnitmXrG|Su/DKYZrPy~zgS)u?dgI53sfs/")
|
||||
).toThrow("FORMBRICKS_ENCRYPTION_KEY is not defined");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import cuid2 from "@paralleldrive/cuid2";
|
||||
import { ENCRYPTION_KEY, FORMBRICKS_ENCRYPTION_KEY } from "@formbricks/lib/constants";
|
||||
import { decryptAES128, symmetricDecrypt, symmetricEncrypt } from "@formbricks/lib/crypto";
|
||||
import { ENCRYPTION_KEY } from "@formbricks/lib/constants";
|
||||
import { symmetricDecrypt, symmetricEncrypt } from "@formbricks/lib/crypto";
|
||||
|
||||
// generate encrypted single use id for the survey
|
||||
export const generateSurveySingleUseId = (isEncrypted: boolean): string => {
|
||||
@@ -21,25 +21,13 @@ export const generateSurveySingleUseId = (isEncrypted: boolean): string => {
|
||||
export const validateSurveySingleUseId = (surveySingleUseId: string): string | undefined => {
|
||||
let decryptedCuid: string | null = null;
|
||||
|
||||
if (surveySingleUseId.length === 64) {
|
||||
if (!FORMBRICKS_ENCRYPTION_KEY) {
|
||||
throw new Error("FORMBRICKS_ENCRYPTION_KEY is not defined");
|
||||
}
|
||||
|
||||
try {
|
||||
decryptedCuid = decryptAES128(FORMBRICKS_ENCRYPTION_KEY, surveySingleUseId);
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
if (!ENCRYPTION_KEY) {
|
||||
throw new Error("ENCRYPTION_KEY is not set");
|
||||
}
|
||||
try {
|
||||
decryptedCuid = symmetricDecrypt(surveySingleUseId, ENCRYPTION_KEY);
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
if (!ENCRYPTION_KEY) {
|
||||
throw new Error("ENCRYPTION_KEY is not set");
|
||||
}
|
||||
try {
|
||||
decryptedCuid = symmetricDecrypt(surveySingleUseId, ENCRYPTION_KEY);
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (cuid2.isCuid(decryptedCuid)) {
|
||||
|
||||
@@ -12,7 +12,6 @@ vi.mock("@formbricks/lib/constants", () => ({
|
||||
FORMBRICKS_API_HOST: "http://localhost:3000",
|
||||
FORMBRICKS_ENVIRONMENT_ID: "test-env-id",
|
||||
ENCRYPTION_KEY: "test-encryption-key",
|
||||
FORMBRICKS_ENCRYPTION_KEY: "test-fb-encryption-key",
|
||||
WEBAPP_URL: "http://localhost:3000",
|
||||
DEFAULT_BRAND_COLOR: "#64748b",
|
||||
AVAILABLE_LOCALES: ["en-US", "de-DE", "pt-BR", "fr-FR", "zh-Hant-TW", "pt-PT"],
|
||||
@@ -49,7 +48,6 @@ vi.mock("@formbricks/lib/env", () => ({
|
||||
FORMBRICKS_API_HOST: "http://localhost:3000",
|
||||
FORMBRICKS_ENVIRONMENT_ID: "test-env-id",
|
||||
ENCRYPTION_KEY: "test-encryption-key",
|
||||
FORMBRICKS_ENCRYPTION_KEY: "test-fb-encryption-key",
|
||||
NODE_ENV: "test",
|
||||
ENTERPRISE_LICENSE_KEY: "test-license-key",
|
||||
},
|
||||
|
||||
@@ -14,7 +14,6 @@ export const WEBAPP_URL =
|
||||
export const SURVEY_URL = env.SURVEY_URL;
|
||||
|
||||
// encryption keys
|
||||
export const FORMBRICKS_ENCRYPTION_KEY = env.FORMBRICKS_ENCRYPTION_KEY || undefined;
|
||||
export const ENCRYPTION_KEY = env.ENCRYPTION_KEY;
|
||||
|
||||
// Other
|
||||
|
||||
@@ -30,7 +30,6 @@ export const env = createEnv({
|
||||
EMAIL_VERIFICATION_DISABLED: z.enum(["1", "0"]).optional(),
|
||||
ENCRYPTION_KEY: z.string(),
|
||||
ENTERPRISE_LICENSE_KEY: z.string().optional(),
|
||||
FORMBRICKS_ENCRYPTION_KEY: z.string().length(24).or(z.string().length(0)).optional(),
|
||||
FORMBRICKS_API_HOST: z
|
||||
.string()
|
||||
.url()
|
||||
@@ -155,7 +154,6 @@ export const env = createEnv({
|
||||
EMAIL_VERIFICATION_DISABLED: process.env.EMAIL_VERIFICATION_DISABLED,
|
||||
ENCRYPTION_KEY: process.env.ENCRYPTION_KEY,
|
||||
ENTERPRISE_LICENSE_KEY: process.env.ENTERPRISE_LICENSE_KEY,
|
||||
FORMBRICKS_ENCRYPTION_KEY: process.env.FORMBRICKS_ENCRYPTION_KEY,
|
||||
FORMBRICKS_API_HOST: process.env.FORMBRICKS_API_HOST,
|
||||
FORMBRICKS_ENVIRONMENT_ID: process.env.FORMBRICKS_ENVIRONMENT_ID,
|
||||
GITHUB_ID: process.env.GITHUB_ID,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import cuid2 from "@paralleldrive/cuid2";
|
||||
import { decryptAES128, symmetricDecrypt, symmetricEncrypt } from "../../lib/crypto";
|
||||
import { symmetricDecrypt, symmetricEncrypt } from "../../lib/crypto";
|
||||
import { env } from "../../lib/env";
|
||||
|
||||
// generate encrypted single use id for the survey
|
||||
@@ -36,15 +36,7 @@ export const validateSurveySingleUseId = (surveySingleUseId: string): string | u
|
||||
throw new Error("ENCRYPTION_KEY is not set");
|
||||
}
|
||||
|
||||
if (surveySingleUseId.length === 64) {
|
||||
if (!env.FORMBRICKS_ENCRYPTION_KEY) {
|
||||
throw new Error("FORMBRICKS_ENCRYPTION_KEY is not defined");
|
||||
}
|
||||
|
||||
decryptedCuid = decryptAES128(env.FORMBRICKS_ENCRYPTION_KEY!, surveySingleUseId);
|
||||
} else {
|
||||
decryptedCuid = symmetricDecrypt(surveySingleUseId, env.ENCRYPTION_KEY);
|
||||
}
|
||||
decryptedCuid = symmetricDecrypt(surveySingleUseId, env.ENCRYPTION_KEY);
|
||||
|
||||
if (cuid2.isCuid(decryptedCuid)) {
|
||||
return decryptedCuid;
|
||||
|
||||
@@ -114,7 +114,6 @@
|
||||
"EMAIL_VERIFICATION_DISABLED",
|
||||
"ENCRYPTION_KEY",
|
||||
"ENTERPRISE_LICENSE_KEY",
|
||||
"FORMBRICKS_ENCRYPTION_KEY",
|
||||
"FORMBRICKS_API_HOST",
|
||||
"FORMBRICKS_ENVIRONMENT_ID",
|
||||
"GITHUB_ID",
|
||||
|
||||
Reference in New Issue
Block a user