Skip to content

extra error message checks and correct escaping in error message - #50136

Merged
MagnusHJensen merged 3 commits into
mainfrom
40074-extra-validation-correct-err-msg
Jul 29, 2026
Merged

extra error message checks and correct escaping in error message#50136
MagnusHJensen merged 3 commits into
mainfrom
40074-extra-validation-correct-err-msg

Conversation

@MagnusHJensen

@MagnusHJensen MagnusHJensen commented Jul 29, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #40074 unreleased bug

image

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

  • Timeouts are implemented and retries are limited to avoid infinite loops

  • If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes
    • Improved configuration profile validation for unescaped special characters in Apple payloads.
    • Error messages now consistently indicate when characters like & and < must be XML-escaped.
    • Updated error examples to show properly escaped guidance.
    • Expanded test coverage to verify the standardized XML-escaping error for additional failing scenarios.

Copilot AI review requested due to automatic review settings July 29, 2026 12:31
@MagnusHJensen
MagnusHJensen requested a review from a team as a code owner July 29, 2026 12:31
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 625b9081-aee4-4a61-b99d-3049e688c73b

📥 Commits

Reviewing files that changed from the base of the PR and between e58394e and 34597c4.

📒 Files selected for processing (2)
  • server/fleet/apple_mdm_test.go
  • server/mdm/apple/mobileconfig/mobileconfig.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • server/mdm/apple/mobileconfig/mobileconfig.go
  • server/fleet/apple_mdm_test.go

Walkthrough

Updated mobileconfig parsing to classify additional plist unmarshal failures as unescaped special-character errors and revised the escaping examples in the returned message. Extended Apple MDM tests with cases for unescaped payload content, identifiers, and names, including assertions for expected error text.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: improved escaping-related error messaging and extra checks.
Description check ✅ Passed The description includes the related issue and testing status, and the template's non-applicable checklist items can be omitted.
Linked Issues check ✅ Passed The code changes address #40074 by improving the special-character error message and adding tests for the escaping cases.
Out of Scope Changes check ✅ Passed The changes stay focused on config profile error handling and tests, with no obvious unrelated additions.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 40074-extra-validation-correct-err-msg

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 error experience when parsing Apple MDM configuration profiles that contain unescaped XML special characters, and adds test coverage to ensure the intended friendly error is returned for common failure cases.

Changes:

  • Expanded ParseConfigProfile error detection to recognize additional XML parsing failures that are likely caused by unescaped characters.
  • Updated the user-facing error message examples for escaping special characters.
  • Added test cases that validate the friendly error message is returned for unescaped characters in the payload, identifier, and name.

Reviewed changes

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

File Description
server/mdm/apple/mobileconfig/mobileconfig.go Broadened parsing error matching and updated the friendly error message returned on parse failures.
server/fleet/apple_mdm_test.go Added new test cases and assertions for the friendly error message when profiles include unescaped XML characters.
Comments suppressed due to low confidence (1)

server/mdm/apple/mobileconfig/mobileconfig.go:172

  • payloadSummary returns the same friendly message but only triggers it for "illegal base64 data". Since ParseConfigProfile now also detects other XML parse errors for unescaped characters, this function can still surface confusing raw parser errors for the same underlying issue. Consider matching the same additional error substrings here, and update the example escaping to the correct XML entities.
		if strings.Contains(err.Error(), "illegal base64 data") {
			return nil, errors.New("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → \\&, < → \\<) and try again.")

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

Comment thread server/mdm/apple/mobileconfig/mobileconfig.go Outdated
Comment thread server/fleet/apple_mdm_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/mdm/apple/mobileconfig/mobileconfig.go`:
- Around line 169-174: Update payloadSummary’s plist.Unmarshal error handling to
map “illegal base64 data”, “invalid character entity”, and “expected attribute
name in element” to the same XML-escaping user-facing error used by
ParseConfigProfile. Prefer extracting and reusing a shared helper so both
parsing paths remain consistent, while returning unrelated errors unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b6839441-72f3-4cd8-8f09-8fd52bc9ca81

📥 Commits

Reviewing files that changed from the base of the PR and between f5ca4b5 and 8b3f226.

📒 Files selected for processing (2)
  • server/fleet/apple_mdm_test.go
  • server/mdm/apple/mobileconfig/mobileconfig.go

Comment thread server/mdm/apple/mobileconfig/mobileconfig.go
Copilot AI review requested due to automatic review settings July 29, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comments suppressed due to low confidence (3)

server/fleet/apple_mdm_test.go:112

  • These new test cases assert an error message that suggests escaping as \\&/\\<, which is not valid XML escaping. If the backend message is corrected to use &amp;/&lt;, update these expected strings accordingly to avoid locking in incorrect guidance.
			testName:     "TestParseConfigProfileUnescapedCharsInPayload",
			mobileconfig: MobileconfigForTest("ValidName", "ValidIdentifier", uuid.NewString(), `<string>Unescaped & < > ' "</string>`),
			shouldFail:   true,
			errString:    new("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → &amp;, < → &lt;) and try again."),
		},
		{
			testName:     "TestParseConfigProfileUnescapedCharsInIdentifier",
			mobileconfig: MobileconfigForTest("ValidName", "Valid<Identifier", uuid.NewString(), `<string>Valid</string>`),
			shouldFail:   true,
			errString:    new("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → &amp;, < → &lt;) and try again."),
		},
		{
			testName:     "TestParseConfigProfileUnescapedCharsInName",
			mobileconfig: MobileconfigForTest("Valid<Name", "ValidIdentifier", uuid.NewString(), `<string>Valid</string>`),
			shouldFail:   true,
			errString:    new("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → &amp;, < → &lt;) and try again."),
		},

server/mdm/apple/mobileconfig/mobileconfig.go:118

  • The error message’s escape examples are incorrect for XML. \& and \< are not valid XML escaping; the examples should show XML entities like &amp; and &lt; so admins can apply the correct fix.
		if strings.Contains(err.Error(), "illegal base64 data") || strings.Contains(err.Error(), "invalid character entity") || strings.Contains(err.Error(), "expected attribute name in element") {
			return nil, errors.New("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → &amp;, < → &lt;) and try again.")
		}

server/mdm/apple/mobileconfig/mobileconfig.go:173

  • Same as above: the escape examples in this error message are not valid XML escaping. Use XML entities like &amp; and &lt; so the guidance is accurate.
		if strings.Contains(err.Error(), "illegal base64 data") || strings.Contains(err.Error(), "invalid character entity") || strings.Contains(err.Error(), "expected attribute name in element") {
			return nil, errors.New("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → &amp;, < → &lt;) and try again.")
		}

Copilot AI review requested due to automatic review settings July 29, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comments suppressed due to low confidence (2)

server/fleet/apple_mdm_test.go:105

  • Same issue here: new("...") is invalid in Go and will not compile; use ptr.String(...) to create the *string.
			errString:    new("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → &amp;, < → &lt;) and try again."),

server/fleet/apple_mdm_test.go:111

  • Same issue here: new("...") is invalid in Go and will not compile; use ptr.String(...) to create the *string.
			errString:    new("The configuration profile contains special characters (&, <, >, ', \") that must be XML-escaped. Please escape them (e.g. & → &amp;, < → &lt;) and try again."),

Comment thread server/fleet/apple_mdm_test.go
@MagnusHJensen
MagnusHJensen merged commit e6118b4 into main Jul 29, 2026
35 checks passed
@MagnusHJensen
MagnusHJensen deleted the 40074-extra-validation-correct-err-msg branch July 29, 2026 12:58
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.08%. Comparing base (f5ca4b5) to head (34597c4).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
server/mdm/apple/mobileconfig/mobileconfig.go 50.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #50136   +/-   ##
=======================================
  Coverage   68.08%   68.08%           
=======================================
  Files        3936     3936           
  Lines      250647   250674   +27     
  Branches    13275    13275           
=======================================
+ Hits       170642   170673   +31     
+ Misses      64693    64690    -3     
+ Partials    15312    15311    -1     
Flag Coverage Δ
backend 69.42% <50.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

MagnusHJensen added a commit that referenced this pull request Jul 29, 2026
…50136) (#50140)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #40074 unreleased bug

Cherry picks: #50136

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes

files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements), JS
inline code is prevented especially for url redirects, and untrusted
data interpolated into shell scripts/commands is validated against shell
metacharacters.
- [ ] Timeouts are implemented and retries are limited to avoid infinite
loops
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved configuration profile validation for unescaped special
characters in Apple payloads.
* Error messages now consistently indicate when characters like `&` and
`<` must be XML-escaped.
  * Updated error examples to show properly escaped guidance.
* Expanded test coverage to verify the standardized XML-escaping error
for additional failing scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

Better error message: Configuration profiles has characters that need escaping

3 participants