-
-
Notifications
You must be signed in to change notification settings - Fork 401
fix: reject invalid SES regions #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const sesRegionSchema = z.string().trim().min(1, "Region is required"); | ||
|
|
||
| export function getValidSesRegions(regions: string[]) { | ||
| return [...new Set(regions.map((region) => region.trim()).filter(Boolean))]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| getValidSesRegions, | ||
| sesRegionSchema, | ||
| } from "~/lib/zod/ses-setting-schema"; | ||
|
|
||
| describe("sesRegionSchema", () => { | ||
| it("rejects empty regions", () => { | ||
| expect(sesRegionSchema.safeParse("").success).toBe(false); | ||
| expect(sesRegionSchema.safeParse(" ").success).toBe(false); | ||
| }); | ||
|
|
||
| it("normalizes valid regions", () => { | ||
| expect(sesRegionSchema.parse(" us-east-1 ")).toBe("us-east-1"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getValidSesRegions", () => { | ||
| it("filters legacy empty regions and removes duplicates", () => { | ||
| expect( | ||
| getValidSesRegions(["", " ", "us-east-1", " us-east-1 ", "eu-west-1"]), | ||
| ).toEqual(["us-east-1", "eu-west-1"]); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { EventType } from "@aws-sdk/client-sesv2"; | |
| import { EmailQueueService } from "./email-queue-service"; | ||
| import { smallNanoid } from "../nanoid"; | ||
| import { logger } from "../logger/log"; | ||
| import { sesRegionSchema } from "~/lib/zod/ses-setting-schema"; | ||
|
|
||
| const GENERAL_EVENTS: EventType[] = [ | ||
| "BOUNCE", | ||
|
|
@@ -27,10 +28,12 @@ export class SesSettingsService { | |
| public static async getSetting( | ||
| region = env.AWS_DEFAULT_REGION | ||
| ): Promise<SesSetting | null> { | ||
| const normalizedRegion = sesRegionSchema.parse(region); | ||
|
|
||
| await this.checkInitialized(); | ||
|
|
||
| if (this.cache[region]) { | ||
| return this.cache[region] as SesSetting; | ||
| if (this.cache[normalizedRegion]) { | ||
| return this.cache[normalizedRegion] as SesSetting; | ||
|
Comment on lines
+31
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Normalize cached settings before using normalized region keys.
Also applies to: 68-72 🤖 Prompt for AI Agents |
||
| } | ||
| return null; | ||
| } | ||
|
|
@@ -62,6 +65,8 @@ export class SesSettingsService { | |
| sendingRateLimit: number; | ||
| transactionalQuota: number; | ||
| }) { | ||
| region = sesRegionSchema.parse(region); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| await this.checkInitialized(); | ||
| if (this.cache[region]) { | ||
| throw new Error(`SesSetting for region ${region} already exists`); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Add tests for the new settings-form states.
Cover loading, retry, the fetched default region, normalized valid input, invalid input, and a rejected quota request.
As per coding guidelines, behavior changes in
apps/webrequire compatible unit or integration tests.Also applies to: 141-148
🤖 Prompt for AI Agents
Source: Coding guidelines