Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Refuse a setup password over 128 characters instead of shortening it

Clauded1d7d5697996
diff --git a/src/components/setup/setup-shell.tsx b/src/components/setup/setup-shell.tsx
index 8012a9b..6ee6cca 100644
--- a/src/components/setup/setup-shell.tsx
+++ b/src/components/setup/setup-shell.tsx
@@ -487,9 +487,11 @@ function SetupForm({
autoComplete="new-password"
disabled={isSubmitting}
error={errors.password}
- helper="At least 15 characters. Let your password manager make one."
+ helper="15 to 128 characters. Let your password manager make one."
label="Password"
- maxLength={128}
+ // No maxLength: the browser would cut a longer password short
+ // without a word, and the account would get a password other
+ // than the one typed. Setup refuses one over 128 instead.
minLength={15}
name="setup-password"
passwordRules="minlength: 20; maxlength: 64; required: lower; required: upper; required: digit; allowed: [-_.!@#$%^&*];"
diff --git a/src/lib/setup.dbtest.ts b/src/lib/setup.dbtest.ts
index 42b01e9..e8996cf 100644
--- a/src/lib/setup.dbtest.ts
+++ b/src/lib/setup.dbtest.ts
@@ -168,6 +168,52 @@ test("setup without a support address is refused before any account exists", asy
);
});
+test("a password over 128 characters is refused with the limit before any account exists (issue #56)", async () => {
+ const tooLong = `Ab7!${"rT9#".repeat(31)}Z`;
+
+ assert.equal(tooLong.length, 129);
+ await assert.rejects(
+ completeSetup(
+ { ...setupInput, password: tooLong },
+ {
+ createAdminAccount: async () => {
+ throw new Error("no account may be created");
+ },
+ database,
+ env,
+ },
+ ),
+ (error: unknown) => {
+ assert.ok(error instanceof SetupError);
+ assert.equal(error.statusCode, 400);
+ assert.deepEqual(error.fieldErrors, {
+ password: "Password must be at most 128 characters",
+ });
+
+ return true;
+ },
+ );
+ assert.equal(await countUsers(), 0);
+ assert.deepEqual(await readSetupState(database), { status: "fresh" });
+
+ // Exactly 128 is still allowed, and the account gets it unchanged.
+ const atLimit = tooLong.slice(0, 128);
+ let given = "";
+
+ await completeSetup(
+ { ...setupInput, password: atLimit },
+ {
+ createAdminAccount: async ({ email, password }) => {
+ given = password;
+ return { userId: await insertUser(email) };
+ },
+ database,
+ env,
+ },
+ );
+ assert.equal(given, atLimit);
+});
+
test("a deployment that sets SUPPORT_EMAIL is not asked for a support address", async () => {
const fixed = { SUPPORT_EMAIL: "Acme Help <[email protected]>" };
const withoutSupportAddress: Record<string, string> = { ...setupInput };
diff --git a/src/lib/setup.ts b/src/lib/setup.ts
index 3e76053..e1643cb 100644
--- a/src/lib/setup.ts
+++ b/src/lib/setup.ts
@@ -142,6 +142,10 @@ const FIELD_MESSAGES: Record<SetupFieldName, string> = {
supportAddress: "Enter an email address people can write to for help",
};
+// A password over the limit is refused, never shortened: the account must
+// be made with exactly what was typed (issue #56).
+const PASSWORD_TOO_LONG_MESSAGE = "Password must be at most 128 characters";
+
function toFieldErrors(error: z.ZodError) {
const fieldErrors: Partial<Record<SetupFieldName, string>> = {};
@@ -150,7 +154,9 @@ function toFieldErrors(error: z.ZodError) {
if (typeof field === "string" && field in FIELD_MESSAGES) {
fieldErrors[field as SetupFieldName] ??=
- FIELD_MESSAGES[field as SetupFieldName];
+ field === "password" && issue.code === "too_big"
+ ? PASSWORD_TOO_LONG_MESSAGE
+ : FIELD_MESSAGES[field as SetupFieldName];
}
}