Skip to content

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 AI review requested due to automatic review settings July 30, 2025 06:40
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 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

Copy link
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

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

Looks good, tests good 👍

I'll get it ported to V16 😄

@nikolajlauridsen nikolajlauridsen merged commit 784e09e into v13/dev Aug 6, 2025
19 checks passed
@nikolajlauridsen nikolajlauridsen deleted the v13/bugfix/support-non-framework-cultures-in-preview branch August 6, 2025 08:34
@nikolajlauridsen
Copy link
Contributor

Looking close at V16 we actually need to parse the culture info there, however, it should allow made up cultures, so I'll hold off porting this 👍

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.

4 participants