Skip to content

Escape snapshot names in libvirt XML - #14201

Open
sureshanaparti wants to merge 1 commit into
apache:4.22from
shapeblue:escape-snapshot-names-libvirt
Open

sureshanaparti wants to merge 1 commit into
apache:4.22from
shapeblue:escape-snapshot-names-libvirt

Conversation

@sureshanaparti

Copy link
Copy Markdown
Contributor

Description

This PR escapes the snapshot names in the three places that build the document: LibvirtCreateVMSnapshotCommandWrapper, generateVMSnapshotXML (snapshot and parent), and the MessageFormat argument in LibvirtManageSnapshotCommandWrapper.
The raw name still goes to snapshotLookupByName, which takes a plain string, not markup.

Uses commons-lang StringEscapeUtils.escapeXml, same as LibvirtVMDef does for the VNC password, so no new dependency. Create and restore escape identically, so existing snapshots are still found by name.

The KVM wrappers build documents by string concatenation and drop the snapshot name straight in.
A name carrying XML metacharacters could close the element early and add arbitrary children, such as a block pointing anywhere on the hypervisor.

Nothing reaching these sinks today can carry a metacharacter: on KVM the vm.instancename.flag path is gated on VMware, hostnames go through NetUtils.verifyDomainNameLabel, and KVMStorageProcessor uses random UUIDs.
This is hardening so the sink no longer depends on its callers.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@sureshanaparti sureshanaparti added this to the 4.22.2 milestone Sep 18, 2026
@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 17.98%. Comparing base (a8c8c18) to head (b8e990d).

Files with missing lines Patch % Lines
...wrapper/LibvirtCreateVMSnapshotCommandWrapper.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14201      +/-   ##
============================================
+ Coverage     17.97%   17.98%   +0.01%     
- Complexity    16184    16191       +7     
============================================
  Files          5930     5930              
  Lines        535615   535615              
  Branches      65582    65582              
============================================
+ Hits          96271    96341      +70     
+ Misses       428377   428301      -76     
- Partials      10967    10973       +6     
Flag Coverage Δ
uitests 4.02% <ø> (ø)
unittests 19.06% <75.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.

@sureshanaparti sureshanaparti changed the title Escape snapshot names in libvirt XML to prevent XML injection Escape snapshot names in libvirt XML Sep 18, 2026
@sureshanaparti
sureshanaparti force-pushed the escape-snapshot-names-libvirt branch from 131ee43 to b8e990d Compare September 18, 2026 12:38
@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19284

@nvazquez nvazquez 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.

Code LGTM

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@JoaoJandre JoaoJandre 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.

CLGTM, did not test it

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-17026)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 52560 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14201-t17026-kvm-ol8.zip
Smoke tests completed. 149 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants