Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix(env): reject REDIS_URL with a username but no password (#3571)

Santhi Prakashfaf59fad8b9b
diff --git a/.env.example b/.env.example
index ef38fe789..31bba1329 100644
--- a/.env.example
+++ b/.env.example
@@ -109,6 +109,10 @@ S3_FORCE_PATH_STYLE="true"
# Redis is optional on a single server. Providers and conversations persist in PostgreSQL.
# Redis shares rate limits, resume events, cancellation and view deduplication, and resumes reply streams.
# Vercel Upstash KV_URL is accepted as an alias for REDIS_URL.
+# Password-only auth (redis-server --requirepass) needs an empty username:
+# redis://:<password>@<host>:<port> or redis://default:<password>@<host>:<port>
+# A named username is only for servers with a configured ACL user; passwordless (`nopass`) ACL users keep an
+# explicitly empty password: redis://<user>:@<host>:<port>
REDIS_URL="redis://redis:6379"
ENCRYPTION_SECRET="change-me-to-a-secure-agent-secret-in-production"
diff --git a/docs/self-hosting/environment-variables.mdx b/docs/self-hosting/environment-variables.mdx
index 95faf5579..0e611af8b 100644
--- a/docs/self-hosting/environment-variables.mdx
+++ b/docs/self-hosting/environment-variables.mdx
@@ -168,6 +168,11 @@ Redis is optional on a single server. Without it, everything works, with these l
Set `REDIS_URL` when you run more than one server process, or when you want replies to survive a reload. When Redis is
configured, the [health endpoint](/self-hosting/docker#check-the-health-endpoint) also checks it.
+For password-only authentication (`redis-server --requirepass`), leave the username empty —
+`redis://:<password>@<host>` — or use the built-in ACL user, `redis://default:<password>@<host>`. A named username
+only works when the server has a matching ACL user; otherwise Redis replies `WRONGPASS invalid username-password
+pair`. Passwordless (`nopass`) ACL users keep an explicitly empty password: `redis://<user>:@<host>`.
+
Saved AI providers and Assistant conversations are kept in PostgreSQL, so they remain available without Redis.
## Web access
diff --git a/packages/env/src/server.test.ts b/packages/env/src/server.test.ts
index 1463a3698..914b3bfe7 100644
--- a/packages/env/src/server.test.ts
+++ b/packages/env/src/server.test.ts
@@ -12,10 +12,14 @@ beforeEach(() => {
"AI_MODEL",
"AI_API_KEY",
"AI_BASE_URL",
+ "REDIS_URL",
])
vi.stubEnv(name, undefined);
});
-afterEach(() => vi.unstubAllEnvs());
+afterEach(() => {
+ vi.unstubAllEnvs();
+ vi.restoreAllMocks();
+});
describe("server web access configuration", () => {
it.each([
@@ -40,3 +44,48 @@ describe("server web access configuration", () => {
expect((await import("./server")).env.WEB_ACCESS_API_KEY).toBeUndefined();
});
});
+
+describe("redis url userinfo", () => {
+ it.each([
+ "redis://localhost:6379",
+ "rediss://localhost:6379/0",
+ "redis://:password@localhost:6379",
+ "redis://default:password@localhost:6379/0",
+ "redis://acl-user:password@localhost:6379",
+ ])("accepts %s", async (url) => {
+ vi.stubEnv("REDIS_URL", url);
+ expect((await import("./server")).env.REDIS_URL).toBe(url);
+ });
+
+ it.each([
+ "redis://acl-user:@localhost:6379", // named ACL user with an empty password (nopass) — AUTH <user> "" is valid
+ "redis://@localhost:6379", // empty userinfo — ioredis treats it like no userinfo and sends no AUTH
+ ])("accepts %s", async (url) => {
+ vi.stubEnv("REDIS_URL", url);
+ expect((await import("./server")).env.REDIS_URL).toBe(url);
+ });
+
+ it.each([
+ "redis://password@localhost:6379", // password in the username slot (userinfo with no colon)
+ ])("rejects %s", async (url) => {
+ vi.stubEnv("REDIS_URL", url);
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
+ await expect(import("./server")).rejects.toThrow("Invalid environment variables");
+ expect(consoleError).toHaveBeenCalledWith(
+ expect.any(String),
+ expect.arrayContaining([
+ expect.objectContaining({ message: expect.stringContaining("userinfo has no password field") }),
+ ]),
+ );
+ });
+
+ it("rejects a malformed URL as a normal validation failure, not a parse crash", async () => {
+ vi.stubEnv("REDIS_URL", "not a url");
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
+ await expect(import("./server")).rejects.toThrow("Invalid environment variables");
+ expect(consoleError).toHaveBeenCalledWith(
+ expect.any(String),
+ expect.arrayContaining([expect.objectContaining({ code: "invalid_format", format: "url" })]),
+ );
+ });
+});
diff --git a/packages/env/src/server.ts b/packages/env/src/server.ts
index d5cd00728..513490e94 100644
--- a/packages/env/src/server.ts
+++ b/packages/env/src/server.ts
@@ -18,6 +18,39 @@ if (workspaceRoot) {
}
}
+// ioredis authenticates as `AUTH <username> <password>`; a bare "redis://value@host" (userinfo with no colon) puts
+// that value in the username slot and Redis rejects the resulting auth. Password-only servers (redis-server
+// --requirepass) need an empty username — "redis://:<pass>@<host>" — or the built-in ACL user,
+// "redis://default:<pass>@<host>". A named user with an explicitly empty password ("redis://user:@host") stays
+// valid: Redis accepts `AUTH <user> ""` for passwordless (`nopass`) ACL users.
+const REDIS_URL_USERINFO_MESSAGE =
+ "REDIS_URL userinfo has no password field. For password-only auth (redis --requirepass) use " +
+ "redis://:<password>@<host>; for ACL users use redis://<user>:<password>@<host> (default is the built-in user; " +
+ "nopass users may keep the password empty, e.g. redis://<user>:@<host>).";
+
+function hasCompleteUserinfo(raw: string): boolean {
+ // Checks run even when the earlier URL-format check has already failed, so this must never throw:
+ // a malformed URL reaching `new URL()` surfaces as an unhandled parse crash instead of a validation
+ // error. Format errors are the URL check's job — only classify complete, parseable URLs here.
+ if (!URL.canParse(raw)) return true;
+
+ // The URL parser normalizes an empty password away ("redis://user:@host" parses like
+ // "redis://user@host"), so the colon that separates the password field must be read from the raw
+ // authority. Userinfo ends at the last "@" before the authority terminator; a userinfo without a
+ // colon is exactly the password-in-username-slot shape ioredis mis-authenticates.
+ const schemeEnd = raw.indexOf("://");
+ if (schemeEnd === -1) return true; // no authority, so no userinfo
+ const authorityStart = schemeEnd + 3;
+ const terminator = raw.slice(authorityStart).search(/[/?#]/);
+ const authority =
+ terminator === -1 ? raw.slice(authorityStart) : raw.slice(authorityStart, authorityStart + terminator);
+ const userinfoEnd = authority.lastIndexOf("@");
+ // `userinfoEnd === 0` is an empty userinfo ("redis://@host") — ioredis reads it exactly like no
+ // userinfo and sends no AUTH, so it passes the same way a missing "@" does.
+ if (userinfoEnd <= 0) return true;
+ return authority.slice(0, userinfoEnd).includes(":");
+}
+
export const env = createEnv({
server: {
// Application
@@ -110,7 +143,10 @@ export const env = createEnv({
S3_FORCE_PATH_STYLE: z.stringbool().default(false),
// AI Agent Workspace (optional until the agent feature is used)
- REDIS_URL: z.url({ protocol: /redis(s)?/ }).optional(),
+ REDIS_URL: z
+ .url({ protocol: /redis(s)?/ })
+ .refine(hasCompleteUserinfo, REDIS_URL_USERINFO_MESSAGE)
+ .optional(),
ENCRYPTION_SECRET: z.string().min(32, "ENCRYPTION_SECRET must be at least 32 characters").optional(),
// Optional search and enhanced reading; custom URLs are operator-controlled Firecrawl services.