π‘οΈ Sentinel: Enforce input length limits on email and password#59
Conversation
Co-authored-by: projectamazonph <286085559+projectamazonph@users.noreply.github.com>
|
π 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
π WalkthroughWalkthroughCheckout, 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. ChangesValidation Boundary Updates
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
π₯ Pre-merge checks | β 5β Passed checks (5 passed)
β¨ Finishing Touchesπ Generate docstrings
π§ͺ Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
π Files selected for processing (2)
src/app/actions/checkout.tssrc/lib/validation.ts
| 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(), |
There was a problem hiding this comment.
π 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
| const canonicalEmail = (invalidMessage: string) => | ||
| z.string().trim().toLowerCase().email(invalidMessage); | ||
| z | ||
| .string() | ||
| .max(254, 'Email is too long.') | ||
| .trim() | ||
| .toLowerCase() | ||
| .email(invalidMessage); |
There was a problem hiding this comment.
π― 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) }));
}
}
JSRepository: projectamazonph/amph-v2
Length of output: 803
π Script executed:
sed -n '1,220p' src/lib/__tests__/validation.test.tsRepository: 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.
π¨ 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