mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
* Add runtime type guards for decrypted JSON data - Create risk-insights-type-guards.ts with validation functions - Replace unsafe type assertions with runtime validation in encryption service - Validate ApplicationHealthReportDetail, OrganizationReportSummary, and OrganizationReportApplication - Add detailed error messages for validation failures - Remove TODO comments for type guard implementation Improves security by preventing malformed data from bypassing type safety and ensures data integrity for decrypted report structures. * test file fix * date validation * add runtime type guards and validation failure tests Issue 1: Missing Test Coverage for Type Guard Validation Failures - Create comprehensive test suite with 17 tests covering all validation scenarios - Test invalid structures, missing fields, wrong types, and edge cases - Verify proper error messages and validation logic for all data types Issue 2: Silent Failure on Validation Errors (Security Concern) - Re-throw validation errors instead of silently returning empty/default data - Add descriptive error messages indicating potential data corruption or tampering - Ensure all validation failures are surfaced as security issues, not swallowed Additional Fix: Date Validation Vulnerability - Validate date strings before creating Date objects to prevent Invalid Date (NaN) - Throw explicit errors for unparseable date strings - Update error handling to catch and properly surface date validation failures * add empty string validation and sanitize error messages - Validate array elements are non-empty strings (atRiskCipherIds, cipherIds, newApplications) - Sanitize validation error messages to prevent information disclosure - Log detailed errors for debugging, re-throw generic messages - Add tests for empty string validation and error message sanitization * add comprehensive validation for scalar strings and numeric ranges - Validate all scalar string fields are non-empty (applicationName, userName, email, cipherId, userGuid) - Add numeric range validation (finite, non-negative) for all count fields - Export type guard functions for testability and reusability - Add 19 new tests covering edge cases (empty strings, NaN, Infinity, negative numbers) * prevent prototype pollution and unexpected property injection in type guards - Validate object prototype is Object.prototype (prevents __proto__ attacks) - Check for dangerous own properties (constructor, prototype) - Strict property enumeration - reject objects with unexpected properties - Add comprehensive security tests (prototype pollution, unexpected props) - Protects against data tampering and information leakage * security: always sanitize error messages to prevent information disclosure - Remove fragile pattern matching in error handlers - Always throw generic error messages by default - Log detailed errors for debugging, never expose to callers - Future-proof against validation error message changes - Prevents disclosure of internal data structure details Applies to all decryption/validation methods in encryption service * security: comprehensive hardening of type validation system CRITICAL FIXES: - Add __proto__ to prototype pollution checks (loop-based) - Remove conditional error sanitization (always sanitize) SECURITY ENHANCEMENTS: - Add integer overflow protection (Number.isSafeInteger) - Add DoS prevention (array/string length limits: 50K/1K) - Strengthen all 4 type guards with 10-layer validation LIMITS: - Max string length: 1,000 characters - Max array length: 50,000 elements - Max safe integer: 2^53 - 1 DOCUMENTATION: - Update code-review-methodology.md with patterns - Update .cursorrules with security best practices - Create comprehensive security audit document All 57 tests passing. No linting errors. Defense-in-depth complete - production ready. * fix: consolidate security constants and add upper bound validation CRITICAL FIXES: - Consolidate MAX_STRING_LENGTH and MAX_ARRAY_LENGTH to file level (DRY) - Add MAX_COUNT constant (10M) for upper bound validation - Apply upper bound checks to all 12 count fields BENEFITS: - Single source of truth for security limits - Prevents business logic issues from extreme values - Easier maintenance and updates
Bitwarden Licensed Code
All source code under this directory is licensed under the Bitwarden License Agreement.