Skip to content

refactor(calm-hub): use centralized strict sanitization policy to prevent XSS#1859

Closed
rocketstack-matt wants to merge 2 commits intofinos:mainfrom
rocketstack-matt:fix/sanitization-security-check
Closed

refactor(calm-hub): use centralized strict sanitization policy to prevent XSS#1859
rocketstack-matt wants to merge 2 commits intofinos:mainfrom
rocketstack-matt:fix/sanitization-security-check

Conversation

@rocketstack-matt
Copy link
Member

Description

Security advisory https://github.com/finos/architecture-as-code/security/dependabot/112 highlights a potential XSS issue, analysis shows this is not an issue with the current implementation, but also that there are a couple of small improvements we could make, which are in this PR.

Refactors CoreSchemaResource to use ResourceValidationConstants.STRICT_SANITIZATION_POLICY
instead of creating a new policy instance. This ensures consistent application of security policies.

Adds a regression test TestSanitizationSecurityShould to verify immunity against
OWASP HtmlPolicyBuilder XSS vulnerability involving noscript and style tags.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🎨 Code style/formatting changes
  • ♻️ Refactoring (no functional changes)
  • ⚡ Performance improvements
  • ✅ Test additions or updates
  • 🔧 Chore (maintenance, dependencies, CI, etc.)

Affected Components

  • CLI (cli/)
  • Shared (shared/)
  • CALM Widgets (calm-widgets/)
  • CALM Hub (calm-hub/)
  • CALM Hub UI (calm-hub-ui/)
  • Documentation (docs/)
  • VS Code Extension (calm-plugins/vscode/)
  • Dependencies
  • CI/CD

Commit Message Format ✅

Testing

  • I have tested my changes locally
  • I have added/updated unit tests
  • All existing tests pass

Checklist

  • My commits follow the conventional commit format
  • I have updated documentation if necessary
  • I have added tests for my changes (if applicable)
  • My changes follow the project's coding standards

rocketstack-matt and others added 2 commits November 27, 2025 10:07
Refactors CoreSchemaResource to use ResourceValidationConstants.STRICT_SANITIZATION_POLICY
instead of creating a new policy instance. This ensures consistent application of
security policies.

Adds a regression test TestSanitizationSecurityShould to verify immunity against
OWASP HtmlPolicyBuilder XSS vulnerability involving noscript and style tags.

Amp-Thread-ID: https://ampcode.com/threads/T-493cb4c5-944e-42fc-8463-e96025b5776f
Co-authored-by: Amp <amp@ampcode.com>
Copilot AI review requested due to automatic review settings November 27, 2025 11:22
@linux-foundation-easycla
Copy link

CLA Not Signed

@github-actions github-actions bot added the calm-hub The Calm Hub Product label Nov 27, 2025
@rocketstack-matt rocketstack-matt deleted the fix/sanitization-security-check branch November 27, 2025 11:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the CoreSchemaResource class to use a centralized strict sanitization policy (ResourceValidationConstants.STRICT_SANITIZATION_POLICY) instead of creating a new policy instance locally. This ensures consistent application of XSS prevention policies across the codebase. The PR also adds a regression test (TestSanitizationSecurityShould) to verify immunity against the OWASP HtmlPolicyBuilder XSS vulnerability involving noscript and style tags referenced in security advisory #112.

  • Centralizes sanitization policy to ensure consistency and easier maintenance
  • Adds comprehensive security regression tests for XSS vulnerability scenarios
  • Aligns CoreSchemaResource with the pattern already used by PatternResource

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
calm-hub/src/main/java/org/finos/calm/resources/CoreSchemaResource.java Refactored to reference the centralized STRICT_SANITIZATION_POLICY constant instead of creating a new HtmlPolicyBuilder instance
calm-hub/src/test/java/org/finos/calm/resources/TestSanitizationSecurityShould.java New test class verifying the strict sanitization policy properly prevents XSS attacks, including specific noscript/style tag vulnerabilities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

public class CoreSchemaResource {

private static final PolicyFactory STRICT_SANITIZATION_POLICY = new HtmlPolicyBuilder().toFactory();
private static final PolicyFactory STRICT_SANITIZATION_POLICY = ResourceValidationConstants.STRICT_SANITIZATION_POLICY;
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using a static import for STRICT_SANITIZATION_POLICY instead of creating a local constant that references it. This would be more consistent with how PatternResource uses the same constant (see line 26 of PatternResource.java).

Current approach:

private static final PolicyFactory STRICT_SANITIZATION_POLICY = ResourceValidationConstants.STRICT_SANITIZATION_POLICY;

Suggested approach:

import static org.finos.calm.resources.ResourceValidationConstants.STRICT_SANITIZATION_POLICY;

This would eliminate the redundant local constant and align with the existing codebase pattern.

Copilot uses AI. Check for mistakes.
public class TestSanitizationSecurityShould {

@Test
public void withstandNoscriptStyleInjectionAttack() {
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Test method names in this codebase use snake_case rather than camelCase. Consider renaming to withstand_noscript_style_injection_attack for consistency with other test files like TestCoreSchemaResourceShould, TestArchitectureResourceShould, and even domain tests like TestDecisionShould.

Suggested change
public void withstandNoscriptStyleInjectionAttack() {
public void withstand_noscript_style_injection_attack() {

Copilot uses AI. Check for mistakes.
}

@Test
public void actAsStrictPolicy() {
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Test method names in this codebase use snake_case rather than camelCase. Consider renaming to act_as_strict_policy for consistency with other test files.

Suggested change
public void actAsStrictPolicy() {
public void act_as_strict_policy() {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

calm-hub The Calm Hub Product

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants