Skip to content

πŸ›‘οΈ Sentinel: Enforce input length limits on email and password#59

Merged
projectamazonph merged 1 commit into
mainfrom
fix/input-length-limits-594834494734848331
Jul 20, 2026
Merged

πŸ›‘οΈ Sentinel: Enforce input length limits on email and password#59
projectamazonph merged 1 commit into
mainfrom
fix/input-length-limits-594834494734848331

Conversation

@projectamazonph

@projectamazonph projectamazonph commented Jul 19, 2026

Copy link
Copy Markdown
Owner

🚨 Severity: MEDIUM
πŸ’‘ Vulnerability: Missing input length validation limits on email and password fields.
🎯 Impact: This allowed attackers to submit extremely large email strings (risk of ReDoS and memory exhaustion) or passwords (risk of heavy scrypt hashing CPU/memory starvation) to block/starve Next.js event loop threads.
πŸ”§ Fix: Added max(254) limits to email fields and max(128) limits to password fields in validation schemas.
βœ… Verification: Successfully passed Vitest tests, ESLint, TypeScript typecheck, and Next.js production build.


PR created automatically by Jules for task 594834494734848331 started by @projectamazonph

Summary by CodeRabbit

  • Bug Fixes
    • Improved checkout validation by rejecting overly long email addresses and invalid pricing tier values.
    • Improved sign-in validation by rejecting passwords longer than 128 characters.
    • Preserved email normalization and format checks for more consistent validation.

Co-authored-by: projectamazonph <286085559+projectamazonph@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

πŸ“ Walkthrough

Walkthrough

Checkout, email, and sign-in schemas now enforce maximum input lengths and a pricing tier upper bound. Existing email trimming, lowercasing, formatting validation, and password minimum validation remain in place.

Changes

Validation Boundary Updates

Layer / File(s) Summary
Checkout input bounds
src/app/actions/checkout.ts
pricingTierId is capped at 100, and checkout email input is capped at 254 characters after canonicalization.
Shared email and password bounds
src/lib/validation.ts
Canonical emails are capped at 254 characters, and sign-in passwords are capped at 128 characters with a dedicated error message.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title clearly matches the main change: enforcing email and password input length limits.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/input-length-limits-594834494734848331

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/actions/checkout.ts`:
- Around line 55-63: Add regression tests for the validation schema containing
pricingTierId and email: verify pricingTierId length 100 succeeds while 101
fails, and email length 254 succeeds while 255 fails. Also verify boundary email
input is trimmed and lowercased in the parsed result, while preserving the
existing validation behavior and meeting the required actions coverage.

In `@src/lib/validation.ts`:
- Around line 29-35: Update canonicalEmail so trim() and toLowerCase() run
before max(254), ensuring the length limit applies to the canonicalized value.
Add tests covering canonical emails at exactly 254 characters and 255
characters.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: beb6dbbc-5bd3-4ddc-b12b-35da45958f61

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 78f1931 and dee176f.

πŸ“’ Files selected for processing (2)
  • src/app/actions/checkout.ts
  • src/lib/validation.ts

Comment on lines +55 to +63
pricingTierId: z.string().min(1).max(100),
// H6: canonicalize the buyer's email so the placeholder user, checkout row,
// and later sign-in all key off the same lowercase value.
email: z.string().trim().toLowerCase().email(),
email: z
.string()
.max(254, 'Email is too long.')
.trim()
.toLowerCase()
.email(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ“ Maintainability & Code Quality | 🟠 Major | ⚑ Quick win

Add regression tests for the new validation boundaries.

Please cover pricingTierId lengths of 100 and 101, email lengths of 254 and 255, and trimming/lowercasing at the boundary. This action-layer change must include tests and maintain the required coverage.

As per coding guidelines, new features must include tests and files under src/app/actions must maintain at least 70% test coverage.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/actions/checkout.ts` around lines 55 - 63, Add regression tests for
the validation schema containing pricingTierId and email: verify pricingTierId
length 100 succeeds while 101 fails, and email length 254 succeeds while 255
fails. Also verify boundary email input is trimmed and lowercased in the parsed
result, while preserving the existing validation behavior and meeting the
required actions coverage.

Source: Coding guidelines

Comment thread src/lib/validation.ts
Comment on lines 29 to +35
const canonicalEmail = (invalidMessage: string) =>
z.string().trim().toLowerCase().email(invalidMessage);
z
.string()
.max(254, 'Email is too long.')
.trim()
.toLowerCase()
.email(invalidMessage);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟑 Minor | ⚑ Quick win

🧩 Analysis chain

🏁 Script executed:

sed -n '1,220p' src/lib/validation.ts
printf '\n---\n'
rg -n "canonicalEmail|signInSchema|createSafeAction|email|password" src/lib -g '*.{ts,tsx}'
printf '\n--- tests ---\n'
rg -n "254|255|128|129|email|password" src -g '*.{test,spec}.ts' -g '*.{test,spec}.tsx'

Repository: projectamazonph/amph-v2

Length of output: 28165


🏁 Script executed:

node - <<'JS'
const { z } = require('zod');

const schema = z.string().max(3, 'too long').trim().toLowerCase();
const cases = [
  'ab',
  ' ab',
  ' ab ',
  ' abc',
  'abcd',
  'abcd ',
];

for (const input of cases) {
  try {
    const out = schema.parse(input);
    console.log(JSON.stringify({ input, ok: true, out, len: out.length }));
  } catch (e) {
    console.log(JSON.stringify({
      input,
      ok: false,
      issues: e.issues?.map(i => ({ code: i.code, message: i.message, path: i.path }))
    }));
  }
}

const emailSchema = z.string().max(254, 'too long').trim().toLowerCase().email('bad');
const base = 'a'.repeat(246) + '`@example.com`'; // 259? let's compute carefully
console.log('base length', base.length);
for (const extra of ['', ' ', '  ']) {
  const input = extra + base + extra;
  try {
    const out = emailSchema.parse(input);
    console.log('email ok', JSON.stringify({ extra: extra.length, inputLen: input.length, outLen: out.length }));
  } catch (e) {
    console.log('email fail', JSON.stringify({ extra: extra.length, inputLen: input.length, issues: e.issues?.map(i => i.message) }));
  }
}
JS

Repository: projectamazonph/amph-v2

Length of output: 803


🏁 Script executed:

sed -n '1,220p' src/lib/__tests__/validation.test.ts

Repository: projectamazonph/amph-v2

Length of output: 5072


Apply the email length limit after canonicalization.
max(254) currently runs on the raw string, so a valid 254-character canonical email with surrounding spaces is rejected before .trim().toLowerCase() normalizes it. Move the length check after normalization, and add a 254/255 boundary test.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/validation.ts` around lines 29 - 35, Update canonicalEmail so trim()
and toLowerCase() run before max(254), ensuring the length limit applies to the
canonicalized value. Add tests covering canonical emails at exactly 254
characters and 255 characters.

@projectamazonph
projectamazonph merged commit 3150027 into main Jul 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant