1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-03 02:03:53 +00:00

Fix validation error: make newApplications field optional in OrganizationReportSummary

The validation functions required the newApplications field to be present,
but this field is not in the type definition and old encrypted data doesn't
have it. This was causing decryption failures with the error:
"Invalid OrganizationReportSummary: missing or invalid fields: newApplications (string[])"

Changes:
- Updated isOrganizationReportSummary() to allow newApplications to be undefined
- Updated validateOrganizationReportSummary() to only validate newApplications if present
- Added comments explaining backward compatibility requirement

This provides backward compatibility with existing encrypted data while still
validating the field when it is present.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2025-10-30 04:42:15 +00:00
parent 55a6e25c0d
commit e8b99d99b8

View File

@@ -230,11 +230,14 @@ export function isOrganizationReportSummary(obj: any): obj is OrganizationReport
Number.isSafeInteger(obj.totalCriticalAtRiskApplicationCount) &&
obj.totalCriticalAtRiskApplicationCount >= 0 &&
obj.totalCriticalAtRiskApplicationCount <= MAX_COUNT &&
Array.isArray(obj.newApplications) &&
obj.newApplications.length <= MAX_ARRAY_LENGTH &&
obj.newApplications.every(
(app: any) => typeof app === "string" && app.length > 0 && app.length <= MAX_STRING_LENGTH,
)
// newApplications is optional (backward compatibility - not in type definition)
(obj.newApplications === undefined ||
(Array.isArray(obj.newApplications) &&
obj.newApplications.length <= MAX_ARRAY_LENGTH &&
obj.newApplications.every(
(app: any) =>
typeof app === "string" && app.length > 0 && app.length <= MAX_STRING_LENGTH,
)))
);
}
@@ -346,8 +349,14 @@ export function validateOrganizationReportSummary(data: any): OrganizationReport
if (typeof data?.totalCriticalAtRiskApplicationCount !== "number") {
missingFields.push("totalCriticalAtRiskApplicationCount (number)");
}
if (!Array.isArray(data?.newApplications)) {
missingFields.push("newApplications (string[])");
// newApplications is optional (backward compatibility - not in type definition)
// Only validate if present
if (
data?.newApplications !== undefined &&
(!Array.isArray(data?.newApplications) ||
!data.newApplications.every((app: any) => typeof app === "string"))
) {
missingFields.push("newApplications (optional string[])");
}
throw new Error(