Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/src/lib/cookieDomain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ describe('sanitizeCookieDomain', () => {
expect(sanitizeCookieDomain(' saplinglearn.com ')).toBe('saplinglearn.com');
});

it('normalizes case (DNS is case-insensitive)', () => {
expect(sanitizeCookieDomain('.SaplingLearn.com')).toBe('.saplinglearn.com');
expect(sanitizeCookieDomain('APP.Example.COM')).toBe('app.example.com');
});

it('rejects overly-broad bare suffixes', () => {
expect(sanitizeCookieDomain('.com')).toBeUndefined();
expect(sanitizeCookieDomain('com')).toBeUndefined();
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/cookieDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export function sanitizeCookieDomain(
raw: string | undefined | null,
): string | undefined {
if (!raw) return undefined;
const value = raw.trim();
// DNS is case-insensitive; normalize to lowercase so a config like
// ".SaplingLearn.com" isn't wrongly rejected by the lowercase-only regex.
const value = raw.trim().toLowerCase();
if (!value || !DOMAIN_RE.test(value)) return undefined;

// Require ≥2 labels in the registrable portion so a bare suffix like ".com"
Expand Down
Loading