Skip to content

Use a regex to filter our invalid culture codes rather than relying on the culture being installed on the operating system #19821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v13/dev
Choose a base branch
from

Conversation

AndyButland
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Addresses: #19817

Description

The linked issue flags a security hardening introduced to ensure that the culture code provided in the preview URL is valid. We did this by verifying that the culture code provided one can be used to construct a CultureInfo. However this failed unnecessarily for culture codes that were valid syntactically but not installed on the operation system and exposed by .NET.

Given we have this to prevent XSS vulnerabilities, it would seem enough to verify the culture code contains only valid characters. So that's what this PR does.

Testing

Preview a page in Umbraco and verify that the provided culture code is accepted and the preview shown.

Manipulate the culture code provided in the querystring to create an invalid one and verify that an exception is thrown.

Release

Needs to be merged/re-applied to Umbraco 16.

…n the culture being installed on the operating system.
@Copilot Copilot AI review requested due to automatic review settings July 30, 2025 06:40
Copy link
Contributor

@Copilot 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 improves the culture code validation in the PreviewController by replacing OS-dependent culture validation with a regex-based approach to prevent XSS attacks. The change addresses a security hardening issue where syntactically valid culture codes were being rejected unnecessarily when not installed on the operating system.

  • Replaces CultureInfo.GetCultureInfo() validation with regex pattern matching
  • Makes validation method internal and adds comprehensive unit tests
  • Updates documentation to clarify the security-focused purpose of the validation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs Implements regex-based culture validation and updates method visibility
tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/PreviewControllerTests.cs Adds comprehensive unit tests for the new validation logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants