Skip to content

Conversation

@r-tome
Copy link
Contributor

@r-tome r-tome commented Oct 16, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-26429

📔 Objective

Add server-side validation to the request body and return the appropriate HTTP status code and error message.
For Policy.Data and SavePolicyModel.Metadata in PUT organizations/{orgId}/policies/{type} > For Policy.Data in PUT organizations/{orgId}/policies/{type}

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@r-tome r-tome marked this pull request as ready for review October 16, 2025 16:18
@r-tome r-tome requested a review from a team as a code owner October 16, 2025 16:18
@r-tome r-tome requested a review from jrmccannon October 16, 2025 16:18
@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

❌ Patch coverage is 96.72131% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.02%. Comparing base (ff4b3eb) to head (f957c91).

Files with missing lines Patch % Lines
...Core/AdminConsole/Utilities/PolicyDataValidator.cs 94.28% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6460      +/-   ##
==========================================
+ Coverage   51.99%   52.02%   +0.02%     
==========================================
  Files        1876     1877       +1     
  Lines       82633    82651      +18     
  Branches     7316     7316              
==========================================
+ Hits        42969    42997      +28     
+ Misses      38008    37995      -13     
- Partials     1656     1659       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

Logo
Checkmarx One – Scan Summary & Details54a486f7-0ae1-434f-83f0-41c3f5240dfe

New Issues (3)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 427
detailsMethod at line 427 of /src/Api/Auth/Controllers/AccountsController.cs gets a parameter from a user request from model. This parameter value flow...
ID: qB2Oh4bvPkc2tAsuqY%2B%2FiPKPcCE%3D
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1537
detailsMethod at line 1537 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
ID: oS5I%2FDxqQus8L80ybnB6qqHIyTo%3D
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1408
detailsMethod at line 1408 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
ID: siIZQHKaoXC15rRHhlVxewk6xUo%3D
Attack Vector
Fixed Issues (1)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 300

…ing of invalid data types in policy updates.
…stModel to utilize PolicyDataValidator for data validation and serialization, removing redundant methods and improving code clarity.
@r-tome r-tome requested a review from jrmccannon October 17, 2025 11:04
…d Metadata properties with empty dictionaries.
@r-tome r-tome requested a review from jrmccannon October 17, 2025 14:23
/// <param name="policyType">The type of policy</param>
/// <returns>Serialized JSON string if data is valid, null if data is null or empty</returns>
/// <exception cref="BadRequestException">Thrown when data validation fails</exception>
public static string? ValidateAndSerialize(Dictionary<string, object>? data, PolicyType policyType)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the nullable and null check now.

/// <param name="metadata">The policy metadata to validate</param>
/// <param name="policyType">The type of policy</param>
/// <returns>Deserialized metadata model, or EmptyMetadataModel if metadata is null, empty, or validation fails</returns>
public static IPolicyMetadataModel ValidateAndDeserializeMetadata(Dictionary<string, object>? metadata, PolicyType policyType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Save as above

@r-tome r-tome requested a review from jrmccannon October 17, 2025 14:55
jrmccannon
jrmccannon previously approved these changes Oct 17, 2025
@jrmccannon jrmccannon dismissed their stale review October 17, 2025 15:07

Didn't see the tests were failing

…empty data and metadata, and remove null assignments in test cases for improved clarity.
@r-tome r-tome requested a review from jrmccannon October 17, 2025 16:17
jrmccannon
jrmccannon previously approved these changes Oct 17, 2025
Copy link
Contributor

@jrmccannon jrmccannon left a comment

Choose a reason for hiding this comment

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

🚀

@r-tome
Copy link
Contributor Author

r-tome commented Oct 23, 2025

@jrmccannon, I have updated the error message to explicitly say which field had the wrong type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants