Xen Security Advisory 530 v2 (CVE-2026-102706,CVE-2026-102707,CVE-2026-102708,CVE-2026-119779,CVE-2026-119780) - XAPI: Multiple RBAC issues (update)

Xen.org security team posted 1 patch 1 week, 6 days ago
Xen Security Advisory 530 v2 (CVE-2026-102706,CVE-2026-102707,CVE-2026-102708,CVE-2026-119779,CVE-2026-119780) - XAPI: Multiple RBAC issues (update)
Posted by Xen.org security team 1 week, 6 days ago
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

 Xen Security Advisory CVE-2026-102706,CVE-2026-102707,CVE-2026-102708,CVE-2026-119779,CVE-2026-119780 / XSA-530
                                                    version 2

                  XAPI: Multiple RBAC issues (update)

UPDATES IN VERSION 2
====================

Public release.

ISSUE DESCRIPTION
=================

XAPI can configure different users with different roles, using Role
Based Access Control.  For more details, see:

  https://docs.xenserver.com/us/en/xencenter/current-release/users/rbac-overview.html#rbac-roles

The pool-admin role is fully privileged.  Notably, users with this role
can also SSH into the host as root.

Some other administrator roles are pool-operator, vm-power-admin and
vm-admin, each of which are authorised to configure and manage various
aspects of the system.

XSA-489 identified some inadequately restricted settings, and introduced
per-key restrictions. Additional API calls have been identified which
were not covered.

 * CVE-2026-102706: Via a crafted VM.create, VM.clone or VM.import call
   a vm-admin can set restricted VM.other_config, VM.platform,
   VM.ha_restart_priority and VM.appliance fields.

 * CVE-2026-102707: Via a Network.create call a vm-admin can set
   restricted Network.other_config and Network.bridge fields.

 * CVE-2026-102708: A vm-power-admin can use the PUT /messages API with
   a crafted message body allowing for arbitrary dom0 symlink/mkdir as
   root.

 * CVE-2026-119779: Any authenticated role can force-fail arbitary tasks
   via the task_id parameter.

 * CVE-2026-119780: A pool-operator can use a crafted
   repository_proxy_url to inject arbitrary yum/dnf .repo directives,
   potentially allowing for a bypass of repository GPG checking.

IMPACT
======

An authenticated user already granted one of pool-operator,
vm-power-admin or vm-admin can escalate their privilege to pool-admin.

Any authenticated user, even with the read-only role, can cause tasks of
more privileged roles to fail.

VULNERABLE SYSTEMS
==================

Systems running all versions of XAPI are vulnerable.

The vulnerability is only exposed if RBAC is configured for the pool,
and certain users are assigned the not-fully-privileged administrator
roles.

MITIGATION
==========

Disable any users (RBAC subjects) which have been configured with the
read-only, vm-operator, vm-admin, vm-power-admin or pool-operator role.

CREDITS
=======

CVE-2026-102706 and CVE-2026-102707 were discovered by Yuliang Xiao.

RESOLUTION
==========

Applying the appropriate set of attached patches resolves this issue.

xsa530/xsa530-??.patch           XAPI master

$ sha256sum xsa530*/*
9a9b493539a22e7eacea083ab89d82b0a65ecba39f6e277379b37c83ea0aeed1  xsa530/xsa530-01.patch
b603422cbe93fa62dd632a43e8fce22b5b59380377a1675f35685d147ce33147  xsa530/xsa530-02.patch
058d33af087e7737dfa22d19116d9713313dc1cce53c5815572928dca8e62f2d  xsa530/xsa530-03.patch
b4448f3c11f43b1d6d7d51f5dae1293182bb2eaf42c5d1489cd5fe065b890420  xsa530/xsa530-04.patch
e8b72b983f82f79b43cd74debf001dd3e937add5281a8f7820e031cb08ee7ff5  xsa530/xsa530-05.patch
cef178c222be027a5a3cc003a894866e86e9c36ccdd977fc792d01d47e4bb96d  xsa530/xsa530-06.patch
4968909dfd7ffedf338e2d51889215006b7ba004b5679683eee702b2488fe22b  xsa530/xsa530-07.patch
aa05daecbff943b9b32955074c191c73fdcbe91e12f9d1288837f6ea85e0168f  xsa530/xsa530-08.patch
8dafb535fa183574897dc2747604389c79f22ba8631833afdf7e7b984a4c7d46  xsa530/xsa530-09.patch
5901dedff57d34aa8899c233fadd7be5077e97fdf0b65c91710365591aa982c7  xsa530/xsa530-10.patch
0b280f976b353052568c143bfba3f99ff5f25493904539d90c77a9eff92a2c22  xsa530/xsa530-11.patch
f16d4a157748b2536b28b93b48d2a3e09e3e4e1dea4e33a1e56c168b489db30c  xsa530/xsa530-12.patch
801c99d73a314b5c5815df947ec0f4667d3cd38a292fb0164d7bb48642f3dac0  xsa530/xsa530-13.patch
$

DEPLOYMENT DURING EMBARGO
=========================

Deployment of the patches and/or mitigations described above (or
others which are substantially similar) is permitted during the
embargo, even on public-facing systems with untrusted guest users and
administrators.

But: Distribution of updated software is prohibited (except to other
members of the predisclosure list).

Predisclosure list members who wish to deploy significantly different
patches and/or mitigations, please contact the Xen Project Security
Team.


(Note: this during-embargo deployment notice is retained in
post-embargo publicly released Xen Project advisories, even though it
is then no longer applicable.  This is to enable the community to have
oversight of the Xen Project Security Team's decisionmaking.)

For more information about permissible uses of embargoed information,
consult the Xen Project community's agreed Security Policy:
  http://www.xenproject.org/security-policy.html
-----BEGIN PGP SIGNATURE-----

iQFABAEBCAAqFiEEI+MiLBRfRHX6gGCng/4UyVfoK9kFAmrzWp4MHHBncEB4ZW4u
b3JnAAoJEIP+FMlX6CvZrekH/RVskWYhSzcCEKskuttjW31mjdhWHNsuHKoTSDdD
kvOe2Pbp27eDCcIYMZQX/uMXwUzmwuMkatq5a+50NslSTQTYBu2nV8ymXfmtwIx2
kKfPu+pOC/Dd2PMBcB6cvTWM0TrY4uO7Zkta5U1RSA0GH2954lAkjQMX8/+CDiO5
NA/DTwIYxTsF1WHcCJhWQMfbwJgmuaDkUz4WXIKOnhLB7FHj5ePTQlCTPTmozl6p
raskKe844jxf3uou87MFzjcWJmxyJOTNhogojucjRg84tIupr0sVa3K2I19pcgBB
hZGfbTIul4U9tLXD4fvYnEZXGUk5POnZttZ/taFtyYg0hBk=
=csuF
-----END PGP SIGNATURE-----
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430073: VM.create bypasses per-key RBAC on other_config and
 platform protected keys

This defeats the _R_POOL_ADMIN per-key gates that XSA-489 added for
VM.other_config:pci and VM.platform:hvm_serial.

Additionally, there are other paths that may bypass the gate: VM clone
and import. Note that the API calls are forwarded to supporter hosts
with session created by pool secret. It needs to be recovered to the
original session for RBAC check.

This is CVE-2026-102706, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/xapi/helpers.ml b/ocaml/xapi/helpers.ml
index 5f1bdae2fd79..ef46341cd143 100644
--- a/ocaml/xapi/helpers.ml
+++ b/ocaml/xapi/helpers.ml
@@ -2579,8 +2579,8 @@ let match_protected_key objname fieldname =
    lower-privileged sessions must be able to manipulate a subset of entries
    (those not protected by a more privileged role).
 *)
-let set_map_with_rbac ~__context ~self ~value ~get_fn ~set_fn ~match_protected
-    ~object_name ~field_name =
+let set_map_with_rbac' ~session_id ~__context ~self ~value ~get_fn ~set_fn
+    ~match_protected ~object_name ~field_name =
   let match_protected = match_protected field_name in
   let module S = Set.Make (String) in
   let create_lookup kvs =
@@ -2647,7 +2647,6 @@ let set_map_with_rbac ~__context ~self ~value ~get_fn ~set_fn ~match_protected
   in
   (* Find the first disallowed permission, indicating that we cannot
      perform the action. *)
-  let session_id = Context.get_session_id __context in
   match
     Rbac.find_first_disallowed_permission ~__context ~session_id ~permissions
   with
@@ -2663,3 +2662,76 @@ let set_map_with_rbac ~__context ~self ~value ~get_fn ~set_fn ~match_protected
         (Rbac.disallowed_permission_exn ~extra_dmsg ~extra_msg ~__context
            ~permission:disallowed ~action
         )
+
+let set_map_with_rbac ~__context ~self ~value ~get_fn ~set_fn ~match_protected
+    ~object_name ~field_name =
+  set_map_with_rbac'
+    ~session_id:(Context.get_session_id __context)
+    ~__context ~self ~value ~get_fn ~set_fn ~match_protected ~object_name
+    ~field_name
+
+(* Try to recover the original session from the task as it is still useful even
+   after passing the RBAC check in API message entry. For example, RBAC check
+   against some keys is only possible when the VM's metadata is received from an
+   input stream while the call has passed RBAC check in API message entry on
+   coordinator and has been forwarded to a supporter host. *)
+let original_session ~__context =
+  match Context.get_session_id __context with
+  | exception Failure _ ->
+      (* No session, check is not needed. *)
+      Ok None
+  | session_id ->
+      let is_forwarding_session =
+        (* Quick check on local session. *)
+        (not (Session_check.is_local_session __context session_id))
+        (* Quick check on forwarded_task as well. *)
+        && Context.forwarded_task __context
+        &&
+        let session = Db.Session.get_record ~__context ~self:session_id in
+        session.API.session_pool && session.API.session_is_local_superuser
+      in
+      if is_forwarding_session then (
+        let ( let* ) = Result.bind in
+        let* task_id =
+          if Context.task_in_database __context then
+            Ok (Context.get_task_id __context)
+          else (
+            warn "%s: no task" __FUNCTION__ ;
+            Error ()
+          )
+        in
+        match Db.Task.get_session ~__context ~self:task_id with
+        | session_id when session_id <> Ref.null ->
+            Ok (Some session_id)
+        | _ ->
+            warn "%s: no session" __FUNCTION__ ;
+            Error ()
+        | exception e ->
+            warn "%s: failed to get originating session: %s" __FUNCTION__
+              (Printexc.to_string e) ;
+            Error ()
+      ) else
+        Ok (Some session_id)
+
+(* With similar purpose of set_map_with_rbac, this is a pure checking function
+   to ensure the session is privileged enough to set values for the protected
+   keys if they present in the map [value]. *)
+let assert_map_with_rbac ~__context ~match_protected ~object_name ~field_name
+    ~value =
+  match original_session ~__context with
+  | Ok None ->
+      ()
+  | Ok (Some session_id) ->
+      set_map_with_rbac' ~session_id ~__context ~self:Ref.null ~value
+        ~get_fn:(fun ~__context:_ ~self:_ -> [])
+        ~set_fn:(fun ~__context:_ ~self:_ ~value:_ -> ())
+        ~match_protected ~object_name ~field_name
+  | Error () ->
+      let action = Printf.sprintf "%s.set_%s" object_name field_name in
+      raise
+        Api_errors.(
+          Server_error
+            ( rbac_permission_denied
+            , [action; "cannot determine the originating session"]
+            )
+        )
diff --git a/ocaml/xapi/import.ml b/ocaml/xapi/import.ml
index 067108cd8f81..b71fb7c2dbd0 100644
--- a/ocaml/xapi/import.ml
+++ b/ocaml/xapi/import.ml
@@ -517,6 +517,10 @@ module VM : HandlerTools = struct
         in
         match import_action with
         | Replace (_, vm_record) | Clean_import vm_record ->
+            Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
+              ~field_name:"other_config" ~value:vm_record.API.vM_other_config ;
+            Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
+              ~field_name:"platform" ~value:vm_record.API.vM_platform ;
             if is_live config then assert_can_live_import __context vm_record ;
             ( if needs_cpu_check config vm_record then
                 let vmm_record =
diff --git a/ocaml/xapi/xapi_vm.ml b/ocaml/xapi/xapi_vm.ml
index f474ca306cb6..2573cb8af024 100644
--- a/ocaml/xapi/xapi_vm.ml
+++ b/ocaml/xapi/xapi_vm.ml
@@ -591,6 +591,10 @@ let create ~__context ~name_label ~name_description ~power_state ~user_version
     else
       other_config
   in
+  Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
+    ~field_name:"other_config" ~value:other_config ;
+  Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
+    ~field_name:"platform" ~value:platform ;
   (* NB apart from the above, parameter validation is delayed until VM.start *)
   let uuid = Uuidx.make () in
   let vm_ref = Ref.make () in
diff --git a/ocaml/xapi/xapi_vm_clone.ml b/ocaml/xapi/xapi_vm_clone.ml
index 25a30eac2785..ea76589db52b 100644
--- a/ocaml/xapi/xapi_vm_clone.ml
+++ b/ocaml/xapi/xapi_vm_clone.ml
@@ -419,10 +419,23 @@ let copy_vm_record ?snapshot_info_record ~__context ~vm ~disk_op ~new_name
 let make_driver_params () =
   [(Constants._sm_epoch_hint, Uuidx.to_string (Uuidx.make ()))]
 
+let assert_protected_map_keys_allowed ~__context ~vm disk_op =
+  match disk_op with
+  | Disk_op_clone | Disk_op_copy _ ->
+      Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
+        ~field_name:"other_config"
+        ~value:(Db.VM.get_other_config ~__context ~self:vm) ;
+      Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
+        ~field_name:"platform"
+        ~value:(Db.VM.get_platform ~__context ~self:vm)
+  | Disk_op_snapshot | Disk_op_checkpoint ->
+      ()
+
 (* NB this function may be called when the VM is suspended for copy/clone
    operations. Snapshot can be done in live. *)
 let clone ?snapshot_info_record ?(ignore_vdis = []) disk_op ~__context ~vm
     ~new_name =
+  assert_protected_map_keys_allowed ~__context ~vm disk_op ;
   Helpers.call_api_functions ~__context (fun rpc session_id ->
       let task_id = Ref.string_of (Context.get_task_id __context) in
       let vbds = Db.VM.get_VBDs ~__context ~self:vm in
diff --git a/ocaml/xapi/xapi_vm_helpers.ml b/ocaml/xapi/xapi_vm_helpers.ml
index f71ab3fd3b36..bcb5e8875cb7 100644
--- a/ocaml/xapi/xapi_vm_helpers.ml
+++ b/ocaml/xapi/xapi_vm_helpers.ml
@@ -1738,3 +1738,8 @@ let check_secureboot_certificates_state ~__context ~self :
         vm_uuid (Printexc.to_string e) ;
       `ok
   )
+
+let assert_protected_map_keys_allowed ~__context ~field_name ~value =
+  let match_protected = Helpers.match_protected_key "VM" in
+  Helpers.assert_map_with_rbac ~__context ~match_protected ~object_name:"vm"
+    ~field_name ~value
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430073: Unit tests for per-key RBAC check on maps of VM

This is CVE-2026-102706, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/tests/suite_alcotest.ml b/ocaml/tests/suite_alcotest.ml
index caedfc564108..8a1b43bcf7dd 100644
--- a/ocaml/tests/suite_alcotest.ml
+++ b/ocaml/tests/suite_alcotest.ml
@@ -73,4 +73,5 @@ let () =
     @ Test_rfb_client_msgtype_parser.tests
     @ Test_tracked_user_agents.tests
     @ Test_cli_args.tests
+    @ Test_vm_protected_keys.tests
     )
diff --git a/ocaml/tests/test_vm_protected_keys.ml b/ocaml/tests/test_vm_protected_keys.ml
new file mode 100644
index 000000000000..ffb31da669c1
--- /dev/null
+++ b/ocaml/tests/test_vm_protected_keys.ml
@@ -0,0 +1,404 @@
+(*
+ * Copyright (C) Cloud Software Group, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+(* Tests for the per-key RBAC guard protecting the "protected keys" of
+   VM.other_config and VM.platform. The keys are declared in the datamodel of VM
+   via [map_keys_roles].
+
+   Paths covered:
+     - the shared helper itself                    (module Helper)
+     - VM.create via [Xapi_vm.create]              (module Create)
+     - VM.clone / VM.copy via [Xapi_vm_clone.assert_protected_map_keys_allowed],
+       and the deliberate NON-gating of
+       VM.snapshot / VM.checkpoint                 (module Clone)
+     - the forwarded path, where the originating
+       session is recovered from the task          (module Forwarded)
+ *)
+
+let rbac_denied = Api_errors.rbac_permission_denied
+
+(* Protected keys and a plain (unprotected) key for control cases. *)
+let oc_pci = [("pci", "0000:00:00.0")]
+
+let pf_hvm = [("hvm_serial", "pty")]
+
+let oc_plain = [("a_plain_key", "value")]
+
+(* The exact permission strings a session must hold to set the keys above. *)
+let perm_add_pci = "vm.add_to_other_config/key:pci"
+
+let perm_add_hvm_serial = "vm.add_to_platform/key:hvm_serial"
+
+let context_with_session base ~is_local_superuser ~rbac_permissions =
+  let session_id =
+    Test_common.make_session ~__context:base ~is_local_superuser
+      ~rbac_permissions ()
+  in
+  Context.make ~session_id "test"
+
+(* A context with no session at all, simulating a trusted internal caller. *)
+let sessionless_context () = Context.make "no-session"
+
+(* A task as the coordinator creates it, recording the session that issued the
+   call in [Task.session]. *)
+let make_task ~__context ~session_id label =
+  let self = Ref.make () in
+  Db.Task.create ~__context ~ref:self ~uuid:(Test_common.make_uuid ())
+    ~name_label:label ~name_description:"" ~created:API.Date.epoch
+    ~finished:API.Date.epoch ~status:`pending ~session:session_id
+    ~resident_on:!Xapi_globs.localhost_ref ~progress:0. ~_type:"<none/>"
+    ~result:"" ~error_info:[] ~allowed_operations:[] ~current_operations:[]
+    ~subtask_of:Ref.null ~other_config:[] ~stunnelpid:(-1L) ~forwarded:true
+    ~forwarded_to:Ref.null ~externalpid:(-1L) ~backtrace:"" ;
+  self
+
+(* The session [Message_forwarding.call_slave_with_session] creates when it
+   forwards a call: pool + local superuser. *)
+let forwarding_session base =
+  Test_common.make_session ~__context:base ~pool:true ~is_local_superuser:true
+    ()
+
+let forwarded_context ~session_id ~task_id =
+  Context.from_forwarded_task ~session_id task_id
+
+let expect_rbac_denied msg f =
+  match f () with
+  | () ->
+      Alcotest.failf "%s: expected %s but the call succeeded" msg rbac_denied
+  | exception Api_errors.Server_error (code, _) when code = rbac_denied ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected %s but got %s" msg rbac_denied
+        (ExnHelper.string_of_exn e)
+
+let expect_ok msg f =
+  match f () with
+  | () ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected success but got %s" msg
+        (ExnHelper.string_of_exn e)
+
+module Helper = struct
+  let assert_allowed ~__context ~field_name ~value =
+    Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context ~field_name
+      ~value
+
+  let test_denies_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_rbac_denied "other_config with protected 'pci'" (fun () ->
+        assert_allowed ~__context ~field_name:"other_config" ~value:oc_pci
+    ) ;
+    expect_rbac_denied "platform with protected 'hvm_serial'" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_allows_with_permission () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:[perm_add_pci]
+    in
+    expect_ok "permitted other_config 'pci'" (fun () ->
+        assert_allowed ~__context ~field_name:"other_config" ~value:oc_pci
+    )
+
+  let test_allows_superuser () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser other_config 'pci'" (fun () ->
+        assert_allowed ~__context ~field_name:"other_config" ~value:oc_pci
+    ) ;
+    expect_ok "superuser platform 'hvm_serial'" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_allows_unprotected_keys () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_ok "unprivileged, no protected keys" (fun () ->
+        assert_allowed ~__context ~field_name:"other_config" ~value:oc_plain
+    )
+
+  let test_allows_sessionless () =
+    let __context = sessionless_context () in
+    expect_ok "sessionless caller, protected 'pci'" (fun () ->
+        assert_allowed ~__context ~field_name:"other_config" ~value:oc_pci
+    )
+
+  let tests =
+    [
+      ("denies unprivileged session", `Quick, test_denies_unprivileged)
+    ; ("allows session with permission", `Quick, test_allows_with_permission)
+    ; ("allows local superuser", `Quick, test_allows_superuser)
+    ; ("allows unprotected keys", `Quick, test_allows_unprotected_keys)
+    ; ("allows sessionless caller", `Quick, test_allows_sessionless)
+    ]
+end
+
+module Create = struct
+  let test_denies_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_rbac_denied "VM.create with platform 'hvm_serial'" (fun () ->
+        ignore (Test_common.make_vm ~__context ~platform:pf_hvm ())
+    ) ;
+    expect_rbac_denied "VM.create with other_config 'pci'" (fun () ->
+        ignore (Test_common.make_vm ~__context ~other_config:oc_pci ())
+    )
+
+  let test_allows_superuser () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser VM.create with platform 'hvm_serial'" (fun () ->
+        ignore (Test_common.make_vm ~__context ~platform:pf_hvm ())
+    )
+
+  let test_allows_with_permission () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:[perm_add_hvm_serial]
+    in
+    expect_ok "permitted VM.create with platform 'hvm_serial'" (fun () ->
+        ignore (Test_common.make_vm ~__context ~platform:pf_hvm ())
+    )
+
+  let test_allows_unprotected_keys () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_ok "unprivileged VM.create, no protected keys" (fun () ->
+        ignore (Test_common.make_vm ~__context ~other_config:oc_plain ())
+    )
+
+  let test_allows_sessionless () =
+    let __context = Test_common.make_test_database () in
+    expect_ok "sessionless VM.create with platform 'hvm_serial'" (fun () ->
+        ignore (Test_common.make_vm ~__context ~platform:pf_hvm ())
+    )
+
+  let tests =
+    [
+      ("denies unprivileged session", `Quick, test_denies_unprivileged)
+    ; ("allows local superuser", `Quick, test_allows_superuser)
+    ; ("allows session with permission", `Quick, test_allows_with_permission)
+    ; ("allows unprotected keys", `Quick, test_allows_unprotected_keys)
+    ; ("allows sessionless caller", `Quick, test_allows_sessionless)
+    ]
+end
+
+module Clone = struct
+  open Xapi_vm_clone
+
+  (* Create the source VM (with a protected key already present) using an
+     internal/sessionless context, so setting up the test bypassing the guard. *)
+  let make_source base ?(other_config = []) ?(platform = []) () =
+    Test_common.make_vm ~__context:base ~other_config ~platform ()
+
+  let copy ~__context ~vm ~disk_op =
+    assert_protected_map_keys_allowed ~__context ~vm disk_op
+
+  let test_denies_clone_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~other_config:oc_pci () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_rbac_denied "clone with protected other_config 'pci'" (fun () ->
+        copy ~__context ~vm ~disk_op:Disk_op_clone
+    )
+
+  let test_denies_copy_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~platform:pf_hvm () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_rbac_denied "copy with protected platform 'hvm_serial'" (fun () ->
+        copy ~__context ~vm ~disk_op:(Disk_op_copy None)
+    )
+
+  let test_allows_snapshot_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~other_config:oc_pci () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_ok "snapshot is not gated (other_config 'pci')" (fun () ->
+        copy ~__context ~vm ~disk_op:Disk_op_snapshot
+    )
+
+  let test_allows_checkpoint_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~platform:pf_hvm () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_ok "checkpoint is not gated (platform 'hvm_serial')" (fun () ->
+        copy ~__context ~vm ~disk_op:Disk_op_checkpoint
+    )
+
+  let test_allows_clone_superuser () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~other_config:oc_pci () in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser clone with protected other_config 'pci'" (fun () ->
+        copy ~__context ~vm ~disk_op:Disk_op_clone
+    )
+
+  let tests =
+    [
+      ("denies unprivileged clone", `Quick, test_denies_clone_unprivileged)
+    ; ("denies unprivileged copy", `Quick, test_denies_copy_unprivileged)
+    ; ("snapshot is not gated", `Quick, test_allows_snapshot_unprivileged)
+    ; ("checkpoint is not gated", `Quick, test_allows_checkpoint_unprivileged)
+    ; ("allows superuser clone", `Quick, test_allows_clone_superuser)
+    ]
+end
+
+(* The forwarded path: the call arrives on a supporter host under a session
+   created from the pool secret. *)
+module Forwarded = struct
+  let assert_allowed = Helper.assert_allowed
+
+  (* The session that actually issued the API call on the coordinator. *)
+  let caller base ~is_local_superuser ~rbac_permissions =
+    Test_common.make_session ~__context:base ~is_local_superuser
+      ~rbac_permissions ()
+
+  let forwarded base ~originator =
+    let session_id = forwarding_session base in
+    let task_id = make_task ~__context:base ~session_id:originator "VM.clone" in
+    forwarded_context ~session_id ~task_id
+
+  let test_denies_unprivileged_originator () =
+    let base = Test_common.make_test_database () in
+    let originator =
+      caller base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    let __context = forwarded base ~originator in
+    expect_rbac_denied "forwarded: originator lacks the permission" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_allows_permitted_originator () =
+    let base = Test_common.make_test_database () in
+    let originator =
+      caller base ~is_local_superuser:false
+        ~rbac_permissions:[perm_add_hvm_serial]
+    in
+    let __context = forwarded base ~originator in
+    expect_ok "forwarded: originator holds the permission" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_allows_superuser_originator () =
+    let base = Test_common.make_test_database () in
+    let originator =
+      caller base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    let __context = forwarded base ~originator in
+    expect_ok "forwarded: originator is local superuser" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_denies_when_task_has_no_session () =
+    let base = Test_common.make_test_database () in
+    let __context = forwarded base ~originator:Ref.null in
+    expect_rbac_denied "forwarded: task records no session" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_denies_when_task_is_dummy () =
+    let base = Test_common.make_test_database () in
+    let session_id = forwarding_session base in
+    let __context =
+      forwarded_context ~session_id ~task_id:(Ref.make_dummy "no-db-task")
+    in
+    expect_rbac_denied "forwarded: no task in database" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_pool_session_without_forwarded_task () =
+    let base = Test_common.make_test_database () in
+    let session_id = forwarding_session base in
+    let __context = Context.make ~session_id "test" in
+    expect_ok "pool superuser session, not forwarded" (fun () ->
+        assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let test_forwarded_task_with_user_session () =
+    let base = Test_common.make_test_database () in
+    let privileged =
+      caller base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    let task_id = make_task ~__context:base ~session_id:privileged "VM.clone" in
+    let session_id =
+      caller base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    let __context = forwarded_context ~session_id ~task_id in
+    expect_rbac_denied
+      "forwarded task with a non-forwarding session is not redirected"
+      (fun () -> assert_allowed ~__context ~field_name:"platform" ~value:pf_hvm
+    )
+
+  let tests =
+    [
+      ( "denies unprivileged originator"
+      , `Quick
+      , test_denies_unprivileged_originator
+      )
+    ; ("allows permitted originator", `Quick, test_allows_permitted_originator)
+    ; ("allows superuser originator", `Quick, test_allows_superuser_originator)
+    ; ( "denies when task has no session"
+      , `Quick
+      , test_denies_when_task_has_no_session
+      )
+    ; ( "denies when task is not in database"
+      , `Quick
+      , test_denies_when_task_is_dummy
+      )
+    ; ( "pool session without forwarded task"
+      , `Quick
+      , test_pool_session_without_forwarded_task
+      )
+    ; ( "forwarded task with user session"
+      , `Quick
+      , test_forwarded_task_with_user_session
+      )
+    ]
+end
+
+let tests =
+  [
+    ("VM protected keys: helper", Helper.tests)
+  ; ("VM protected keys: VM.create", Create.tests)
+  ; ("VM protected keys: VM.clone/copy/snapshot", Clone.tests)
+  ; ("VM protected keys: forwarded call", Forwarded.tests)
+  ]
diff --git a/ocaml/xapi/xapi_vm_clone.mli b/ocaml/xapi/xapi_vm_clone.mli
index 05843952fca7..16e13a7a9c5d 100644
--- a/ocaml/xapi/xapi_vm_clone.mli
+++ b/ocaml/xapi/xapi_vm_clone.mli
@@ -62,3 +62,7 @@ val clone :
   -> vm:[`VM] API.Ref.t
   -> new_name:string
   -> [`VM] Ref.t
+
+(* For test purpose only *)
+val assert_protected_map_keys_allowed :
+  __context:Context.t -> vm:[`VM] API.Ref.t -> disk_op_t -> unit
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430073: VM.create bypasses RBAC on HA restart priority and
 appliance

VM.create only needs the VM admin role, but it takes a whole VM record,
including fields whose setters need a higher role. Two of them are
checked in this PR:

  - ha_restart_priority: a VM with "restart" is protected by HA and takes
    resources from the pool's point of view.
  - appliance: is managed from pool's point of view as well.

There are other VM fields which currently require higher role. But one
of them, ha_always_run, is deprecated. Others seem not necessary to be
managed by higher role, or from the pool's point of view.

This is CVE-2026-102706, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/xapi/helpers.ml b/ocaml/xapi/helpers.ml
index ef46341cd143..c4cd232b1256 100644
--- a/ocaml/xapi/helpers.ml
+++ b/ocaml/xapi/helpers.ml
@@ -2735,3 +2735,28 @@ let assert_map_with_rbac ~__context ~match_protected ~object_name ~field_name
             , [action; "cannot determine the originating session"]
             )
         )
+
+(* With similar purpose of assert_map_with_rbac, check if setting a non-default
+   value on a field of an object is allowed. *)
+let assert_field_value_with_rbac ~__context ~object_name ~field_name ~is_default
+    =
+  if not is_default then
+    let action = Printf.sprintf "%s.set_%s" object_name field_name in
+    let permission = String.lowercase_ascii action in
+    match original_session ~__context with
+    | Ok None ->
+        ()
+    | Ok (Some session_id) ->
+        if not (Rbac.is_access_allowed ~__context ~session_id ~permission) then
+          raise
+            (Rbac.disallowed_permission_exn ~extra_dmsg:"" ~extra_msg:""
+               ~__context ~permission ~action
+            )
+    | Error () ->
+        raise
+          Api_errors.(
+            Server_error
+              ( rbac_permission_denied
+              , [action; "cannot determine the originating session"]
+              )
+          )
diff --git a/ocaml/xapi/import.ml b/ocaml/xapi/import.ml
index b71fb7c2dbd0..16ebb4c9264c 100644
--- a/ocaml/xapi/import.ml
+++ b/ocaml/xapi/import.ml
@@ -521,6 +521,10 @@ module VM : HandlerTools = struct
               ~field_name:"other_config" ~value:vm_record.API.vM_other_config ;
             Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
               ~field_name:"platform" ~value:vm_record.API.vM_platform ;
+            (* The appliance is cleared on import, so it isn't checked. *)
+            Xapi_vm_helpers.assert_protected_field_allowed ~__context
+              ~field_name:"ha_restart_priority"
+              ~is_default:(vm_record.API.vM_ha_restart_priority = "") ;
             if is_live config then assert_can_live_import __context vm_record ;
             ( if needs_cpu_check config vm_record then
                 let vmm_record =
diff --git a/ocaml/xapi/xapi_vm.ml b/ocaml/xapi/xapi_vm.ml
index 2573cb8af024..da87a18752c4 100644
--- a/ocaml/xapi/xapi_vm.ml
+++ b/ocaml/xapi/xapi_vm.ml
@@ -595,6 +595,10 @@ let create ~__context ~name_label ~name_description ~power_state ~user_version
     ~field_name:"other_config" ~value:other_config ;
   Xapi_vm_helpers.assert_protected_map_keys_allowed ~__context
     ~field_name:"platform" ~value:platform ;
+  Xapi_vm_helpers.assert_protected_field_allowed ~__context
+    ~field_name:"ha_restart_priority" ~is_default:(ha_restart_priority = "") ;
+  Xapi_vm_helpers.assert_protected_field_allowed ~__context
+    ~field_name:"appliance" ~is_default:(appliance = Ref.null) ;
   (* NB apart from the above, parameter validation is delayed until VM.start *)
   let uuid = Uuidx.make () in
   let vm_ref = Ref.make () in
diff --git a/ocaml/xapi/xapi_vm_clone.ml b/ocaml/xapi/xapi_vm_clone.ml
index ea76589db52b..3d62851e5209 100644
--- a/ocaml/xapi/xapi_vm_clone.ml
+++ b/ocaml/xapi/xapi_vm_clone.ml
@@ -431,11 +431,22 @@ let assert_protected_map_keys_allowed ~__context ~vm disk_op =
   | Disk_op_snapshot | Disk_op_checkpoint ->
       ()
 
+let assert_protected_fields_allowed ~__context ~vm disk_op =
+  match disk_op with
+  | Disk_op_clone | Disk_op_copy _ ->
+      (* The appliance of the new VM is reset, so it isn't checked. *)
+      Xapi_vm_helpers.assert_protected_field_allowed ~__context
+        ~field_name:"ha_restart_priority"
+        ~is_default:(Db.VM.get_ha_restart_priority ~__context ~self:vm = "")
+  | Disk_op_snapshot | Disk_op_checkpoint ->
+      ()
+
 (* NB this function may be called when the VM is suspended for copy/clone
    operations. Snapshot can be done in live. *)
 let clone ?snapshot_info_record ?(ignore_vdis = []) disk_op ~__context ~vm
     ~new_name =
   assert_protected_map_keys_allowed ~__context ~vm disk_op ;
+  assert_protected_fields_allowed ~__context ~vm disk_op ;
   Helpers.call_api_functions ~__context (fun rpc session_id ->
       let task_id = Ref.string_of (Context.get_task_id __context) in
       let vbds = Db.VM.get_VBDs ~__context ~self:vm in
diff --git a/ocaml/xapi/xapi_vm_helpers.ml b/ocaml/xapi/xapi_vm_helpers.ml
index bcb5e8875cb7..c6270a6a8245 100644
--- a/ocaml/xapi/xapi_vm_helpers.ml
+++ b/ocaml/xapi/xapi_vm_helpers.ml
@@ -1743,3 +1743,7 @@ let assert_protected_map_keys_allowed ~__context ~field_name ~value =
   let match_protected = Helpers.match_protected_key "VM" in
   Helpers.assert_map_with_rbac ~__context ~match_protected ~object_name:"vm"
     ~field_name ~value
+
+let assert_protected_field_allowed ~__context ~field_name ~is_default =
+  Helpers.assert_field_value_with_rbac ~__context ~object_name:"vm" ~field_name
+    ~is_default
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430073: Unit tests for RBAC check on protected fields of VM

This is CVE-2026-102706, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/tests/suite_alcotest.ml b/ocaml/tests/suite_alcotest.ml
index 8a1b43bcf7dd..3e13d3fbccad 100644
--- a/ocaml/tests/suite_alcotest.ml
+++ b/ocaml/tests/suite_alcotest.ml
@@ -74,4 +74,5 @@ let () =
     @ Test_tracked_user_agents.tests
     @ Test_cli_args.tests
     @ Test_vm_protected_keys.tests
+    @ Test_vm_protected_fields.tests
     )
diff --git a/ocaml/tests/test_vm_protected_fields.ml b/ocaml/tests/test_vm_protected_fields.ml
new file mode 100644
index 000000000000..bc42eb96f3f4
--- /dev/null
+++ b/ocaml/tests/test_vm_protected_fields.ml
@@ -0,0 +1,300 @@
+(*
+ * Copyright (C) Cloud Software Group, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+(* Tests for the RBAC guard protecting the fields of VM whose setters need a
+   higher role than VM.create: setting such a field to anything but its default
+   needs the permission of its setter.
+
+   Paths covered:
+     - the shared helper itself                    (module Helper)
+     - VM.create via [Xapi_vm.create]              (module Create)
+     - VM.clone / VM.copy via [Xapi_vm_clone.assert_protected_fields_allowed],
+       and the deliberate NON-gating of
+       VM.snapshot / VM.checkpoint                 (module Clone)
+ *)
+
+let rbac_denied = Api_errors.rbac_permission_denied
+
+(* The exact permission strings a session must hold to set the fields. *)
+let perm_set_ha_restart_priority = "vm.set_ha_restart_priority"
+
+let perm_set_appliance = "vm.set_appliance"
+
+let context_with_session base ~is_local_superuser ~rbac_permissions =
+  let session_id =
+    Test_common.make_session ~__context:base ~is_local_superuser
+      ~rbac_permissions ()
+  in
+  Context.make ~session_id "test"
+
+(* A context with no session at all, simulating a trusted internal caller. *)
+let sessionless_context () = Context.make "no-session"
+
+let unprivileged base =
+  context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+
+let make_appliance ~__context =
+  let ref = Ref.make () in
+  Db.VM_appliance.create ~__context ~ref ~uuid:(Test_common.make_uuid ())
+    ~name_label:"appliance" ~name_description:"" ~allowed_operations:[]
+    ~current_operations:[] ;
+  ref
+
+let expect_rbac_denied msg f =
+  match f () with
+  | () ->
+      Alcotest.failf "%s: expected %s but the call succeeded" msg rbac_denied
+  | exception Api_errors.Server_error (code, _) when code = rbac_denied ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected %s but got %s" msg rbac_denied
+        (ExnHelper.string_of_exn e)
+
+let expect_ok msg f =
+  match f () with
+  | () ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected success but got %s" msg
+        (ExnHelper.string_of_exn e)
+
+module Helper = struct
+  let assert_allowed ~__context ~is_default =
+    Xapi_vm_helpers.assert_protected_field_allowed ~__context
+      ~field_name:"ha_restart_priority" ~is_default
+
+  let test_denies_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let __context = unprivileged base in
+    expect_rbac_denied "non-default value" (fun () ->
+        assert_allowed ~__context ~is_default:false
+    )
+
+  let test_allows_default () =
+    let base = Test_common.make_test_database () in
+    let __context = unprivileged base in
+    expect_ok "default value" (fun () ->
+        assert_allowed ~__context ~is_default:true
+    )
+
+  let test_allows_with_permission () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:[perm_set_ha_restart_priority]
+    in
+    expect_ok "allowed non-default value" (fun () ->
+        assert_allowed ~__context ~is_default:false
+    )
+
+  let test_denies_other_permission () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:[perm_set_appliance]
+    in
+    expect_rbac_denied "permission of another field" (fun () ->
+        assert_allowed ~__context ~is_default:false
+    )
+
+  let test_allows_superuser () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser non-default value" (fun () ->
+        assert_allowed ~__context ~is_default:false
+    )
+
+  let test_allows_sessionless () =
+    let __context = sessionless_context () in
+    expect_ok "sessionless caller, non-default value" (fun () ->
+        assert_allowed ~__context ~is_default:false
+    )
+
+  let tests =
+    [
+      ("denies unprivileged session", `Quick, test_denies_unprivileged)
+    ; ("allows default value", `Quick, test_allows_default)
+    ; ("allows session with permission", `Quick, test_allows_with_permission)
+    ; ( "denies session with another permission"
+      , `Quick
+      , test_denies_other_permission
+      )
+    ; ("allows local superuser", `Quick, test_allows_superuser)
+    ; ("allows sessionless caller", `Quick, test_allows_sessionless)
+    ]
+end
+
+module Create = struct
+  let test_denies_ha_restart_priority () =
+    let base = Test_common.make_test_database () in
+    let __context = unprivileged base in
+    expect_rbac_denied "VM.create with ha_restart_priority 'restart'" (fun () ->
+        ignore (Test_common.make_vm ~__context ~ha_restart_priority:"restart" ())
+    )
+
+  let test_denies_appliance () =
+    let base = Test_common.make_test_database () in
+    let appliance = make_appliance ~__context:base in
+    let __context = unprivileged base in
+    expect_rbac_denied "VM.create with an appliance" (fun () ->
+        ignore (Test_common.make_vm ~__context ~appliance ())
+    )
+
+  let test_allows_defaults () =
+    let base = Test_common.make_test_database () in
+    let __context = unprivileged base in
+    expect_ok "unprivileged VM.create with defaults" (fun () ->
+        ignore (Test_common.make_vm ~__context ())
+    )
+
+  let test_allows_ha_always_run () =
+    (* Deprecated, and only effective with the "restart" priority. *)
+    let base = Test_common.make_test_database () in
+    let __context = unprivileged base in
+    expect_ok "unprivileged VM.create with ha_always_run" (fun () ->
+        ignore (Test_common.make_vm ~__context ~ha_always_run:true ())
+    )
+
+  let test_allows_with_permission () =
+    let base = Test_common.make_test_database () in
+    let appliance = make_appliance ~__context:base in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:[perm_set_ha_restart_priority; perm_set_appliance]
+    in
+    expect_ok "allowed VM.create with both fields" (fun () ->
+        ignore
+          (Test_common.make_vm ~__context ~ha_restart_priority:"restart"
+             ~appliance ()
+          )
+    )
+
+  let test_allows_superuser () =
+    let base = Test_common.make_test_database () in
+    let appliance = make_appliance ~__context:base in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser VM.create with both fields" (fun () ->
+        ignore
+          (Test_common.make_vm ~__context ~ha_restart_priority:"restart"
+             ~appliance ()
+          )
+    )
+
+  let test_allows_sessionless () =
+    let __context = Test_common.make_test_database () in
+    expect_ok "sessionless VM.create with ha_restart_priority 'restart'"
+      (fun () ->
+        ignore (Test_common.make_vm ~__context ~ha_restart_priority:"restart" ())
+    )
+
+  let tests =
+    [
+      ( "denies unprivileged ha_restart_priority"
+      , `Quick
+      , test_denies_ha_restart_priority
+      )
+    ; ("denies unprivileged appliance", `Quick, test_denies_appliance)
+    ; ("allows defaults", `Quick, test_allows_defaults)
+    ; ("allows ha_always_run", `Quick, test_allows_ha_always_run)
+    ; ("allows session with permissions", `Quick, test_allows_with_permission)
+    ; ("allows local superuser", `Quick, test_allows_superuser)
+    ; ("allows sessionless caller", `Quick, test_allows_sessionless)
+    ]
+end
+
+module Clone = struct
+  open Xapi_vm_clone
+
+  let make_source base ?(ha_restart_priority = "") ?(appliance = Ref.null) () =
+    Test_common.make_vm ~__context:base ~ha_restart_priority ~appliance ()
+
+  let check ~__context ~vm ~disk_op =
+    assert_protected_fields_allowed ~__context ~vm disk_op
+
+  let test_denies_clone_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~ha_restart_priority:"restart" () in
+    let __context = unprivileged base in
+    expect_rbac_denied "clone with ha_restart_priority 'restart'" (fun () ->
+        check ~__context ~vm ~disk_op:Disk_op_clone
+    )
+
+  let test_denies_copy_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~ha_restart_priority:"restart" () in
+    let __context = unprivileged base in
+    expect_rbac_denied "copy with ha_restart_priority 'restart'" (fun () ->
+        check ~__context ~vm ~disk_op:(Disk_op_copy None)
+    )
+
+  let test_allows_appliance_unprivileged () =
+    (* The appliance of the new VM is reset. *)
+    let base = Test_common.make_test_database () in
+    let appliance = make_appliance ~__context:base in
+    let vm = make_source base ~appliance () in
+    let __context = unprivileged base in
+    expect_ok "clone of a VM in an appliance" (fun () ->
+        check ~__context ~vm ~disk_op:Disk_op_clone
+    )
+
+  let test_allows_snapshot_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~ha_restart_priority:"restart" () in
+    let __context = unprivileged base in
+    expect_ok "snapshot is not gated" (fun () ->
+        check ~__context ~vm ~disk_op:Disk_op_snapshot
+    )
+
+  let test_allows_checkpoint_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~ha_restart_priority:"restart" () in
+    let __context = unprivileged base in
+    expect_ok "checkpoint is not gated" (fun () ->
+        check ~__context ~vm ~disk_op:Disk_op_checkpoint
+    )
+
+  let test_allows_clone_superuser () =
+    let base = Test_common.make_test_database () in
+    let vm = make_source base ~ha_restart_priority:"restart" () in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser clone with ha_restart_priority 'restart'" (fun () ->
+        check ~__context ~vm ~disk_op:Disk_op_clone
+    )
+
+  let tests =
+    [
+      ("denies unprivileged clone", `Quick, test_denies_clone_unprivileged)
+    ; ("denies unprivileged copy", `Quick, test_denies_copy_unprivileged)
+    ; ( "allows clone of a VM in an appliance"
+      , `Quick
+      , test_allows_appliance_unprivileged
+      )
+    ; ("snapshot is not gated", `Quick, test_allows_snapshot_unprivileged)
+    ; ("checkpoint is not gated", `Quick, test_allows_checkpoint_unprivileged)
+    ; ("allows superuser clone", `Quick, test_allows_clone_superuser)
+    ]
+end
+
+let tests =
+  [
+    ("VM protected fields: helper", Helper.tests)
+  ; ("VM protected fields: VM.create", Create.tests)
+  ; ("VM protected fields: VM.clone/copy/snapshot", Clone.tests)
+  ]
diff --git a/ocaml/xapi/xapi_vm_clone.mli b/ocaml/xapi/xapi_vm_clone.mli
index 16e13a7a9c5d..b0936d9301fd 100644
--- a/ocaml/xapi/xapi_vm_clone.mli
+++ b/ocaml/xapi/xapi_vm_clone.mli
@@ -66,3 +66,7 @@ val clone :
 (* For test purpose only *)
 val assert_protected_map_keys_allowed :
   __context:Context.t -> vm:[`VM] API.Ref.t -> disk_op_t -> unit
+
+(* For test purpose only *)
+val assert_protected_fields_allowed :
+  __context:Context.t -> vm:[`VM] API.Ref.t -> disk_op_t -> unit
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430074: Network.create lets vm-admin reconfigure dom0 IP and HIMN
 listener

The minimum allowed role of invoking Network.create is vm-admin. But the
[other_config] map of a Network object (except the key specified by
[map_keys_roles]) are of minimum role of pool-operator. So the [other_config]
parameter of Network.create should be checked to not allow two
particular keys which might impact the host internal management network
(HIMN) when the caller of the API is of vm-admin role. The HIMN is
allowed to be managed with pool-operator or higher privilege levels.

Additionally, there is another path (import) to get the privilege
escalation happen.

This is CVE-2026-102707, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/idl/datamodel.ml b/ocaml/idl/datamodel.ml
index 861e48852207..97e26278ccc3 100644
--- a/ocaml/idl/datamodel.ml
+++ b/ocaml/idl/datamodel.ml
@@ -1493,6 +1493,11 @@ module Network = struct
                   ("folder", _R_VM_OP)
                 ; ("XenCenter.CustomFields.*", _R_VM_OP)
                 ; ("XenCenterCreateInProgress", _R_VM_OP)
+                ; (* Host Internal Management Network markers. Redundant for
+                     the writer_roles, but they generate the per-key rules that
+                     Network.create checks, its default role being VM admin. *)
+                  ("is_guest_installer_network", _R_POOL_OP)
+                ; ("is_host_internal_management_network", _R_POOL_OP)
                 ]
               ~published:rel_rio
           ; field
diff --git a/ocaml/xapi/import.ml b/ocaml/xapi/import.ml
index 16ebb4c9264c..080582b47309 100644
--- a/ocaml/xapi/import.ml
+++ b/ocaml/xapi/import.ml
@@ -1273,6 +1273,17 @@ module Net : HandlerTools = struct
     | Found_net _ ->
         handle_dry_run __context config rpc session_id state x precheck_result
     | Create net_record ->
+        (* The [session_id] passed to Client.Network.create_from_record
+           (and hence to Network.create) may have been created by
+           Helpers.call_api_functions with a higher privilege level than the
+           requesting client session. This is intentional, but it means the
+           per-key RBAC check inside Network.create would evaluate that
+           elevated session and let protected keys through. The import
+           metadata is caller-controlled, so enforce the check here instead,
+           where Helpers.assert_map_with_rbac can still resolve the
+           originating session. *)
+        Xapi_network_helpers.assert_protected_map_keys_allowed ~__context
+          ~field_name:"other_config" ~value:net_record.API.network_other_config ;
         let net =
           log_reraise
             ("failed to create Network with name_label "
diff --git a/ocaml/xapi/xapi_network.ml b/ocaml/xapi/xapi_network.ml
index dfa15d0a18ab..d35de92696a5 100644
--- a/ocaml/xapi/xapi_network.ml
+++ b/ocaml/xapi/xapi_network.ml
@@ -235,6 +235,8 @@ let rec choose_bridge_name bridges =
 
 let create ~__context ~name_label ~name_description ~mTU ~other_config ~bridge
     ~managed ~tags =
+  Xapi_network_helpers.assert_protected_map_keys_allowed ~__context
+    ~field_name:"other_config" ~value:other_config ;
   with_lock mutex (fun () ->
       let networks = Db.Network.get_all ~__context in
       let bridges =
diff --git a/ocaml/xapi/xapi_network_helpers.ml b/ocaml/xapi/xapi_network_helpers.ml
index 0a6bcd47c0e2..0e1932abfda6 100644
--- a/ocaml/xapi/xapi_network_helpers.ml
+++ b/ocaml/xapi/xapi_network_helpers.ml
@@ -123,3 +123,8 @@ let assert_network_compatible_with_sriov ~__context ~pif ~network =
                 )
             )
   )
+
+let assert_protected_map_keys_allowed ~__context ~field_name ~value =
+  let match_protected = Helpers.match_protected_key "network" in
+  Helpers.assert_map_with_rbac ~__context ~match_protected
+    ~object_name:"network" ~field_name ~value
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430074: Don't take bridge from an import for network creation

When VM.import decides to create a network that doesn't exist on this
pool, the original bridge is meaningless to this pool. So make
Network.create choose the bridge, and always create a managed
network.

This also eliminates the bypass of the bridge_blacklist.

This is CVE-2026-102707, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/xapi/import.ml b/ocaml/xapi/import.ml
index 080582b47309..9a2254e13998 100644
--- a/ocaml/xapi/import.ml
+++ b/ocaml/xapi/import.ml
@@ -1284,6 +1284,12 @@ module Net : HandlerTools = struct
            originating session. *)
         Xapi_network_helpers.assert_protected_map_keys_allowed ~__context
           ~field_name:"other_config" ~value:net_record.API.network_other_config ;
+        (* The bridge from the import is meaningless to this pool.
+           Network.create will choose the bridge. A network created during
+           import must be a managed one. *)
+        let net_record =
+          {net_record with API.network_bridge= ""; network_managed= true}
+        in
         let net =
           log_reraise
             ("failed to create Network with name_label "
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430074: Unit tests for per-key RBAC check on maps of Network

This is CVE-2026-102707, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/tests/suite_alcotest.ml b/ocaml/tests/suite_alcotest.ml
index 3e13d3fbccad..184a56c92a7e 100644
--- a/ocaml/tests/suite_alcotest.ml
+++ b/ocaml/tests/suite_alcotest.ml
@@ -75,4 +75,5 @@ let () =
     @ Test_cli_args.tests
     @ Test_vm_protected_keys.tests
     @ Test_vm_protected_fields.tests
+    @ Test_network_protected_keys.tests
     )
diff --git a/ocaml/tests/test_network_protected_keys.ml b/ocaml/tests/test_network_protected_keys.ml
new file mode 100644
index 000000000000..0027ed8e9aed
--- /dev/null
+++ b/ocaml/tests/test_network_protected_keys.ml
@@ -0,0 +1,264 @@
+(*
+ * Copyright (C) Cloud Software Group, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+(* Tests for the per-key RBAC guard protecting the "protected keys" of
+   Network.other_config. The keys are declared in the datamodel of Network via
+   [map_keys_roles].
+
+   Paths covered:
+     - the shared helper itself                  (module Helper)
+     - Network.create via [Xapi_network.create]  (module Create)
+ *)
+
+let rbac_denied = Api_errors.rbac_permission_denied
+
+let oc_guest_installer = [(Xapi_globs.is_guest_installer_network, "true")]
+
+let oc_himn = [(Xapi_globs.is_host_internal_management_network, "true")]
+
+let oc_folder = [("folder", "/my/folder")]
+
+let oc_custom_field = [("XenCenter.CustomFields.colour", "blue")]
+
+(* A key that map_keys_roles does not mention at all. *)
+let oc_plain = [("a_plain_key", "value")]
+
+(* The permission a session must hold to set a given key. The key is lowercased
+   in the permission name, and for a wildcard entry it is the pattern rather
+   than the concrete key that appears. *)
+let perm_of_key key = "network.add_to_other_config/key:" ^ key
+
+let perm_add_guest_installer = perm_of_key Xapi_globs.is_guest_installer_network
+
+let perm_add_himn = perm_of_key Xapi_globs.is_host_internal_management_network
+
+(* Everything a VM administrator holds, straight from the generated role
+   definitions. This is Network.create's default allowed role, and so the
+   privilege level the guard has to hold the line against: it covers the
+   XenCenter keys of other_config, but neither the writer role of the field nor
+   the HIMN markers. *)
+let vm_admin_permissions =
+  List.map
+    (fun permission -> permission.Db_actions.role_name_label)
+    Rbac_static.permissions_of_role_vm_admin
+
+let context_with_session base ~is_local_superuser ~rbac_permissions =
+  let session_id =
+    Test_common.make_session ~__context:base ~is_local_superuser
+      ~rbac_permissions ()
+  in
+  Context.make ~session_id "test"
+
+(* A context with no session at all, simulating a trusted internal caller. *)
+let sessionless_context () = Context.make "no-session"
+
+let expect_rbac_denied msg f =
+  match f () with
+  | () ->
+      Alcotest.failf "%s: expected %s but the call succeeded" msg rbac_denied
+  | exception Api_errors.Server_error (code, _) when code = rbac_denied ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected %s but got %s" msg rbac_denied
+        (ExnHelper.string_of_exn e)
+
+let expect_ok msg f =
+  match f () with
+  | () ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected success but got %s" msg
+        (ExnHelper.string_of_exn e)
+
+module Helper = struct
+  let assert_allowed ~__context ~value =
+    Xapi_network_helpers.assert_protected_map_keys_allowed ~__context
+      ~field_name:"other_config" ~value
+
+  let test_denies_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_rbac_denied "other_config with 'is_guest_installer_network'"
+      (fun () -> assert_allowed ~__context ~value:oc_guest_installer
+    ) ;
+    expect_rbac_denied "other_config with 'is_host_internal_management_network'"
+      (fun () -> assert_allowed ~__context ~value:oc_himn
+    )
+
+  let test_allows_with_permission () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:[perm_add_guest_installer; perm_add_himn]
+    in
+    expect_ok "permitted 'is_guest_installer_network'" (fun () ->
+        assert_allowed ~__context ~value:oc_guest_installer
+    ) ;
+    expect_ok "permitted 'is_host_internal_management_network'" (fun () ->
+        assert_allowed ~__context ~value:oc_himn
+    )
+
+  let test_allows_superuser () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser 'is_guest_installer_network'" (fun () ->
+        assert_allowed ~__context ~value:oc_guest_installer
+    )
+
+  let test_allows_unprotected_keys () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_ok "unprivileged, no protected keys" (fun () ->
+        assert_allowed ~__context ~value:oc_plain
+    )
+
+  let test_allows_sessionless () =
+    let __context = sessionless_context () in
+    expect_ok "sessionless caller, 'is_guest_installer_network'" (fun () ->
+        assert_allowed ~__context ~value:oc_guest_installer
+    )
+
+  let test_vm_admin_cannot_write_himn () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:vm_admin_permissions
+    in
+    expect_ok "VM admin, 'folder'" (fun () ->
+        assert_allowed ~__context ~value:oc_folder
+    ) ;
+    expect_ok "VM admin, 'XenCenter.CustomFields.*'" (fun () ->
+        assert_allowed ~__context ~value:oc_custom_field
+    ) ;
+    expect_rbac_denied "VM admin, 'is_guest_installer_network'" (fun () ->
+        assert_allowed ~__context ~value:oc_guest_installer
+    ) ;
+    expect_rbac_denied "VM admin, 'is_host_internal_management_network'"
+      (fun () -> assert_allowed ~__context ~value:oc_himn
+    )
+
+  let tests =
+    [
+      ("denies unprivileged session", `Quick, test_denies_unprivileged)
+    ; ("allows session with permission", `Quick, test_allows_with_permission)
+    ; ("allows local superuser", `Quick, test_allows_superuser)
+    ; ("allows unprotected keys", `Quick, test_allows_unprotected_keys)
+    ; ("allows sessionless caller", `Quick, test_allows_sessionless)
+    ; ( "VM admin cannot write HIMN markers"
+      , `Quick
+      , test_vm_admin_cannot_write_himn
+      )
+    ]
+end
+
+module Create = struct
+  let create ~__context ~other_config =
+    ignore
+      (Xapi_network.create ~__context ~name_label:"net"
+         ~name_description:"description" ~mTU:1500L ~other_config ~bridge:""
+         ~managed:true ~tags:[]
+      )
+
+  let test_denies_unprivileged () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_rbac_denied "Network.create with 'is_guest_installer_network'"
+      (fun () -> create ~__context ~other_config:oc_guest_installer
+    ) ;
+    expect_rbac_denied
+      "Network.create with 'is_host_internal_management_network'" (fun () ->
+        create ~__context ~other_config:oc_himn
+    )
+
+  let test_denies_vm_admin () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:vm_admin_permissions
+    in
+    expect_ok "VM admin Network.create, no protected keys" (fun () ->
+        create ~__context ~other_config:oc_plain
+    ) ;
+    expect_ok "VM admin Network.create with 'folder'" (fun () ->
+        create ~__context ~other_config:oc_folder
+    ) ;
+    expect_rbac_denied
+      "VM admin Network.create with 'is_guest_installer_network'" (fun () ->
+        create ~__context ~other_config:oc_guest_installer
+    ) ;
+    expect_rbac_denied
+      "VM admin Network.create with 'is_host_internal_management_network'"
+      (fun () -> create ~__context ~other_config:oc_himn
+    )
+
+  let test_allows_with_permission () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false
+        ~rbac_permissions:[perm_add_guest_installer]
+    in
+    expect_ok "permitted Network.create with 'is_guest_installer_network'"
+      (fun () -> create ~__context ~other_config:oc_guest_installer
+    )
+
+  let test_allows_superuser () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:true ~rbac_permissions:[]
+    in
+    expect_ok "superuser Network.create with 'is_guest_installer_network'"
+      (fun () -> create ~__context ~other_config:oc_guest_installer
+    )
+
+  let test_allows_unprotected_keys () =
+    let base = Test_common.make_test_database () in
+    let __context =
+      context_with_session base ~is_local_superuser:false ~rbac_permissions:[]
+    in
+    expect_ok "unprivileged Network.create, no protected keys" (fun () ->
+        create ~__context ~other_config:oc_plain
+    )
+
+  (* Create_networks makes the real HIMN at start of day from a context with no
+     session; that must keep working. *)
+  let test_allows_sessionless () =
+    let __context = Test_common.make_test_database () in
+    expect_ok "sessionless Network.create with both HIMN markers" (fun () ->
+        create ~__context ~other_config:(oc_guest_installer @ oc_himn)
+    )
+
+  let tests =
+    [
+      ("denies unprivileged session", `Quick, test_denies_unprivileged)
+    ; ("denies VM admin session", `Quick, test_denies_vm_admin)
+    ; ("allows session with permission", `Quick, test_allows_with_permission)
+    ; ("allows local superuser", `Quick, test_allows_superuser)
+    ; ("allows unprotected keys", `Quick, test_allows_unprotected_keys)
+    ; ("allows sessionless caller", `Quick, test_allows_sessionless)
+    ]
+end
+
+let tests =
+  [
+    ("Network protected keys: helper", Helper.tests)
+  ; ("Network protected keys: Network.create", Create.tests)
+  ]
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430075: Symlink/directory creation traversal via PUT /messages
 body

Add sanity check against the ref, object_uuid and uuid in the message
XML body in PUT requests. These fields will be used to create symlinks
on dom0's filesystem.

This is CVE-2026-102708, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/xapi/xapi_message.ml b/ocaml/xapi/xapi_message.ml
index 30a425b02a7c..97c669d2e324 100644
--- a/ocaml/xapi/xapi_message.ml
+++ b/ocaml/xapi/xapi_message.ml
@@ -56,6 +56,15 @@ let in_memory_cache_length_default = 256
 (* We use the timestamp to name the file. For consistency, use this function *)
 let timestamp_to_string f = Printf.sprintf "%0.5f" f
 
+let is_valid_uuid str = String.length str = 36 && Uuidx.is_uuid str
+
+let is_opaque_ref str =
+  let prefix = "OpaqueRef:" in
+  String.starts_with ~prefix str
+  &&
+  let n = String.length prefix in
+  is_valid_uuid (String.sub str n (String.length str - n))
+
 (************* Marshalling/unmarshalling functions ************)
 
 let to_xml output _ref gen message =
@@ -88,6 +97,10 @@ let to_xml output _ref gen message =
   tag "message" message_subtags ()
 
 let of_xml input =
+  let fn = __FUNCTION__ in
+  let bad_xml tag dat =
+    failwith (Printf.sprintf "%s: bad XML: tag:%s data:'%s'" fn tag dat)
+  in
   let current_elt = ref "" in
   let message =
     ref
@@ -124,17 +137,20 @@ let of_xml input =
             message :=
               {!message with API.message_cls= Record_util.cls_of_string dat}
         | "obj_uuid" ->
+            if not (is_valid_uuid dat) then bad_xml "obj_uuid" dat ;
             message := {!message with API.message_obj_uuid= dat}
         | "timestamp" ->
             message :=
               {!message with API.message_timestamp= Date.of_iso8601 dat}
         | "uuid" ->
+            if not (is_valid_uuid dat) then bad_xml "uuid" dat ;
             message := {!message with API.message_uuid= dat}
         | "body" ->
             message := {!message with API.message_body= dat}
         | "generation" ->
             gen := Int64.of_string dat
         | "ref" ->
+            if not (is_opaque_ref dat) then bad_xml "ref" dat ;
             _ref := dat
         | _ ->
             failwith "Bad XML!"
@@ -145,7 +161,15 @@ let of_xml input =
   in
   try
     f () ;
-    (!gen, Ref.of_string !_ref, !message)
+    let msg = !message in
+    (* See if any keys are missing. *)
+    [
+      ("ref", !_ref)
+    ; ("uuid", msg.API.message_uuid)
+    ; ("obj_uuid", msg.API.message_obj_uuid)
+    ]
+    |> List.iter (fun (tag, dat) -> if dat = "" then bad_xml tag dat) ;
+    (!gen, Ref.of_string !_ref, msg)
   with e -> Backtrace.is_important e ; raise e
 
 let export_xml messages =
@@ -855,6 +879,22 @@ let register_event_hook () =
   repopulate_cache () ;
   Xapi_event.Message.get_since_for_events := get_since_for_events
 
+let assert_query_matches_body ~cls ~uuid message =
+  let mismatch reason =
+    failwith (Printf.sprintf "Xapi_message.handler: %s" reason)
+  in
+  if message.API.message_cls <> cls then
+    mismatch
+      (Printf.sprintf "Message cls '%s' does not match query cls '%s'"
+         (Record_util.cls_to_string message.API.message_cls)
+         (Record_util.cls_to_string cls)
+      ) ;
+  if message.API.message_obj_uuid <> uuid then
+    mismatch
+      (Printf.sprintf "Message obj_uuid '%s' does not match query uuid '%s'"
+         message.API.message_obj_uuid uuid
+      )
+
 (** Handler for PUTing messages to a host.
     	Query params: { cls=<obj class>, uuid=<obj uuid> } *)
 let handler (req : Http.Request.t) fd _ =
@@ -904,6 +944,9 @@ let handler (req : Http.Request.t) fd _ =
             Xmlm.make_input (`Channel (Unix.in_channel_of_descr fd))
           in
           let messages = import_xml xml_in in
+          List.iter
+            (function _, _, m -> assert_query_matches_body ~cls ~uuid m)
+            messages ;
           List.iter
             (function _, r, m -> ignore (write ~__context ~_ref:r ~message:m))
             messages ;
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430075: Unit test for sanity check of message body

This is CVE-2026-102708, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/tests/dune b/ocaml/tests/dune
index 04671057c5e5..72bfd8ae785a 100644
--- a/ocaml/tests/dune
+++ b/ocaml/tests/dune
@@ -54,6 +54,7 @@
     xapi_database
     xapi_internal
     xml-light2
+    xmlm
   )
   (deps
     (source_tree test_data)
diff --git a/ocaml/tests/suite_alcotest.ml b/ocaml/tests/suite_alcotest.ml
index 184a56c92a7e..25c2130caabe 100644
--- a/ocaml/tests/suite_alcotest.ml
+++ b/ocaml/tests/suite_alcotest.ml
@@ -46,6 +46,7 @@ let () =
      ; ("Test_bios_strings", Test_bios_strings.test)
      ; ("Test_certificates", Test_certificates.test)
      ; ("Test_caller_limit", Test_caller_limit.test)
+     ; ("Test_message", Test_message.test)
      ]
     @ Test_guest_agent.tests
     @ Test_nm.tests
diff --git a/ocaml/tests/test_message.ml b/ocaml/tests/test_message.ml
new file mode 100644
index 000000000000..b2b768d1f5e4
--- /dev/null
+++ b/ocaml/tests/test_message.ml
@@ -0,0 +1,215 @@
+(*
+ * Copyright (C) Cloud Software Group, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+module Date = Clock.Date
+
+let ok_ref = "OpaqueRef:9d2c1f80-3e4b-4a6d-8b12-0f7a5c3e9d44"
+
+let ok_uuid = "7f3e2a10-88c4-4e5b-a9d1-2c6b0f4e7a35"
+
+let ok_obj_uuid = "b4a0f7e2-0c5d-4a11-9f3c-6d2e8a17c9b1"
+
+let xml_decl = {|<?xml version="1.0" encoding="UTF-8"?>|}
+
+let message_xml ?(_ref = ok_ref) ?(uuid = ok_uuid) ?(obj_uuid = ok_obj_uuid)
+    ?(cls = "VM") () =
+  String.concat ""
+    [
+      "<message>"
+    ; Printf.sprintf "<ref>%s</ref>" _ref
+    ; "<name>VM_SHUTDOWN</name>"
+    ; "<priority>5</priority>"
+    ; Printf.sprintf "<cls>%s</cls>" cls
+    ; Printf.sprintf "<obj_uuid>%s</obj_uuid>" obj_uuid
+    ; "<timestamp>20260818T09:14:22Z</timestamp>"
+    ; Printf.sprintf "<uuid>%s</uuid>" uuid
+    ; "<body>Guest requested shutdown</body>"
+    ; "</message>"
+    ]
+
+let test_message =
+  {
+    API.message_name= "VM_SHUTDOWN"
+  ; API.message_uuid= ok_uuid
+  ; API.message_priority= 5L
+  ; API.message_cls= `VM
+  ; API.message_obj_uuid= ok_obj_uuid
+  ; API.message_timestamp= Date.of_iso8601 "20260818T09:14:22Z"
+  ; API.message_body= "Guest requested shutdown"
+  }
+
+let of_xml_string str = Xapi_message.of_xml (Xmlm.make_input (`String (0, str)))
+
+let import_string str =
+  Xapi_message.import_xml (Xmlm.make_input (`String (0, str)))
+
+let check_rejected what str =
+  match of_xml_string str with
+  | exception Failure _ ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected Failure, got %s" what (Printexc.to_string e)
+  | _ ->
+      Alcotest.failf "%s: expected a rejection, but the message parsed" what
+
+let check_accepted what str =
+  match of_xml_string str with
+  | _gen, _ref, message ->
+      (_ref, message)
+  | exception e ->
+      Alcotest.failf "%s: expected success, got %s" what (Printexc.to_string e)
+
+let test_accepts_well_formed () =
+  let _ref, message = check_accepted "well-formed" (message_xml ()) in
+  Alcotest.(check string) "ref" ok_ref (Ref.string_of _ref) ;
+  Alcotest.(check string) "uuid" ok_uuid message.API.message_uuid ;
+  Alcotest.(check string) "obj_uuid" ok_obj_uuid message.API.message_obj_uuid ;
+  Alcotest.(check string) "name" "VM_SHUTDOWN" message.API.message_name
+
+let test_expect_failure_bad_ref () =
+  List.iter
+    (fun _ref -> check_rejected ("ref " ^ _ref) (message_xml ~_ref ()))
+    [
+      "OpaqueRef:../../../../etc/cron.d/x"
+    ; "../../../../etc/cron.d/x"
+    ; "OpaqueRef:9d2c1f80-3e4b-4a6d-8b12-0f7a5c3e9d44/../../x"
+    ; "OpaqueRef:NULL"
+    ; "OpaqueRef:not-a-uuid"
+    ; "OpaqueRef:"
+    ; "DummyRef:|" ^ ok_uuid ^ "|a-name"
+    ; ok_uuid
+    ]
+
+let test_expect_failure_bad_uuid () =
+  List.iter
+    (fun uuid -> check_rejected ("uuid " ^ uuid) (message_xml ~uuid ()))
+    [
+      "../../../root/.ssh/authorized_keys"
+    ; ok_uuid ^ "/../../x"
+    ; "not-a-uuid"
+    ; ok_ref
+    ]
+
+let test_expect_failure_bad_obj_uuid () =
+  List.iter
+    (fun obj_uuid ->
+      check_rejected ("obj_uuid " ^ obj_uuid) (message_xml ~obj_uuid ())
+    )
+    ["../../../tmp/x"; ok_obj_uuid ^ "/../../x"; "not-a-uuid"]
+
+let test_expect_failure_missing_identifiers () =
+  List.iter
+    (fun (what, xml) -> check_rejected what xml)
+    [
+      ( "empty ref"
+      , Printf.sprintf
+          "<message><ref></ref><uuid>%s</uuid><obj_uuid>%s</obj_uuid></message>"
+          ok_uuid ok_obj_uuid
+      )
+    ; ( "self-closing uuid"
+      , Printf.sprintf
+          "<message><ref>%s</ref><uuid/><obj_uuid>%s</obj_uuid></message>"
+          ok_ref ok_obj_uuid
+      )
+    ; ( "absent obj_uuid"
+      , Printf.sprintf "<message><ref>%s</ref><uuid>%s</uuid></message>" ok_ref
+          ok_uuid
+      )
+    ; ("no identifiers at all", "<message/>")
+    ]
+
+(* Whatever to_xml writes must still be accepted by of_xml, or cross-pool
+   migration would stop replicating messages. *)
+let test_export_import_round_trip () =
+  let body = Xapi_message.export_xml [(Ref.of_string ok_ref, test_message)] in
+  match import_string body with
+  | [(_gen, _ref, message)] ->
+      Alcotest.(check string) "ref" ok_ref (Ref.string_of _ref) ;
+      Alcotest.(check string) "uuid" ok_uuid message.API.message_uuid ;
+      Alcotest.(check string)
+        "obj_uuid" ok_obj_uuid message.API.message_obj_uuid ;
+      Alcotest.(check string) "name" "VM_SHUTDOWN" message.API.message_name ;
+      Alcotest.(check string)
+        "body" "Guest requested shutdown" message.API.message_body
+  | messages ->
+      Alcotest.failf "expected 1 message, got %d" (List.length messages)
+
+(* import_xml parses the whole batch before the handler writes any of it, so one
+   bad message aborts the import instead of leaving its neighbours written. *)
+let test_import_expect_failure_whole_batch () =
+  let good = xml_decl ^ message_xml () in
+  let bad = xml_decl ^ message_xml ~_ref:"OpaqueRef:../../../etc/x" () in
+  List.iter
+    (fun (what, body) ->
+      match import_string body with
+      | exception Failure _ ->
+          ()
+      | exception e ->
+          Alcotest.failf "%s: expected Failure, got %s" what
+            (Printexc.to_string e)
+      | _ ->
+          Alcotest.failf "%s: expected the batch to be rejected" what
+    )
+    [("bad message first", bad ^ good); ("bad message last", good ^ bad)] ;
+  Alcotest.(check int)
+    "a batch of good messages still imports" 2
+    (List.length (import_string (good ^ good)))
+
+(* The query params name the object the request was admitted for, and the
+   handler has already resolved them in the database. A message that claims a
+   different class or object must not be written under it. *)
+let test_assert_query_matches_body () =
+  let expect_no_failure what ~cls ~uuid message =
+    match Xapi_message.assert_query_matches_body ~cls ~uuid message with
+    | () ->
+        ()
+    | exception e ->
+        Alcotest.failf "%s: unexpected %s" what (Printexc.to_string e)
+  in
+  let expect_failure what ~cls ~uuid message =
+    match Xapi_message.assert_query_matches_body ~cls ~uuid message with
+    | () ->
+        Alcotest.failf "%s: expected a rejection" what
+    | exception Failure _ ->
+        ()
+    | exception e ->
+        Alcotest.failf "%s: expected Failure, got %s" what (Printexc.to_string e)
+  in
+  expect_no_failure "matching cls and obj_uuid" ~cls:`VM ~uuid:ok_obj_uuid
+    test_message ;
+  expect_failure "body claims another class" ~cls:`Host ~uuid:ok_obj_uuid
+    test_message ;
+  expect_failure "body claims another object" ~cls:`VM
+    ~uuid:"11111111-2222-3333-4444-555555555555" test_message
+
+let test =
+  [
+    ("test_accepts_well_formed", `Quick, test_accepts_well_formed)
+  ; ("test_expect_failure_bad_ref", `Quick, test_expect_failure_bad_ref)
+  ; ("test_expect_failure_bad_uuid", `Quick, test_expect_failure_bad_uuid)
+  ; ( "test_expect_failure_bad_obj_uuid"
+    , `Quick
+    , test_expect_failure_bad_obj_uuid
+    )
+  ; ( "test_expect_failure_missing_identifiers"
+    , `Quick
+    , test_expect_failure_missing_identifiers
+    )
+  ; ("test_export_import_round_trip", `Quick, test_export_import_round_trip)
+  ; ( "test_import_expect_failure_whole_batch"
+    , `Quick
+    , test_import_expect_failure_whole_batch
+    )
+  ; ("test_assert_query_matches_body", `Quick, test_assert_query_matches_body)
+  ]
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430077: Low-privilege user can force-fail arbitrary tasks via
 task_id parameter

A low-privilege user could use [task_id] parameter in some APIs to set
other users' tasks failed. So now setting a task failed only if the task
is owned by the user (caller).

For a call or request, the check can be placed in the following 3
places alternatively:
1. Xapi_http.assert_credentials_ok if rbac_check is true in HTTP
   actions;
2. Server_helpers.do_dispatch if the call is a regular XenAPI call;
3. others by calling Xapi_http.with_context. This is a best-to-have
   place in case a call or request doesn't go to the 2 places above.

This is CVE-2026-119779, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/xapi/server_helpers.ml b/ocaml/xapi/server_helpers.ml
index 326e47ee463b..eedf1b163427 100644
--- a/ocaml/xapi/server_helpers.ml
+++ b/ocaml/xapi/server_helpers.ml
@@ -126,6 +126,18 @@ module Helper = struct
   end)
 end
 
+let can_own_task ?session_id task_id =
+  try
+    Context.with_context ~quiet:true ?session_id "can_own_task"
+      (fun __context -> TaskHelper.assert_op_valid ~__context task_id
+    ) ;
+    true
+  with e ->
+    warn "Task %s provided in the request can't be handled by the caller: %s"
+      (Ref.string_of task_id)
+      (ExnHelper.string_of_exn e) ;
+    false
+
 let do_dispatch ?session_id ?forward_op ?self:_ supports_async called_fn_name
     op_fn marshaller fd http_req label sync_ty generate_task_for =
   (* if the call has been forwarded to us, then they are responsible for completing the task, so we don't need to complete it *)
@@ -140,6 +152,20 @@ let do_dispatch ?session_id ?forward_op ?self:_ supports_async called_fn_name
       Context.of_http_req ?session_id ~internal_async_subtask ~generate_task_for
         ~supports_async ~label ~http_req ~fd ()
     in
+    if
+      Context.task_in_database __context
+      && not (can_own_task ?session_id (Context.get_task_id __context))
+    then
+      raise
+        Api_errors.(
+          Server_error
+            ( rbac_permission_denied
+            , [
+                String.lowercase_ascii called_fn_name
+              ; "The task provided in the request belongs to another subject."
+              ]
+            )
+        ) ;
 
     Constants.when_tgroups_enabled (fun () ->
         let identity =
diff --git a/ocaml/xapi/server_helpers.mli b/ocaml/xapi/server_helpers.mli
index 9155469e26ba..6944db32ea86 100644
--- a/ocaml/xapi/server_helpers.mli
+++ b/ocaml/xapi/server_helpers.mli
@@ -39,6 +39,13 @@ val exec_with_subtask :
   -> (__context:Context.t -> 'b)
   -> 'b
 
+val can_own_task : ?session_id:API.ref_session -> API.ref_task -> bool
+(** [can_own_task ?session_id task] is true when [session_id] can handle
+    [task]. A task provided by a request is caller-controlled, so it has to be
+    checked before anything is done with it. Only call this for a task
+    that is really in the database: the check cannot resolve a dummy ref and
+    would refuse every unprivileged caller. *)
+
 (* used by auto-generated code in server.ml *)
 val my_assoc : string -> (string * 'a) list -> 'a
 
diff --git a/ocaml/xapi/taskHelper.ml b/ocaml/xapi/taskHelper.ml
index 1990ac2ce7ad..56a42d9a88c9 100644
--- a/ocaml/xapi/taskHelper.ml
+++ b/ocaml/xapi/taskHelper.ml
@@ -62,13 +62,19 @@ let rbac_assert_permission_fn = ref None
 
 let are_auth_user_ids_of_sessions_equal ~__context s1 s2 =
   Context.with_tracing ~__context __FUNCTION__ @@ fun __context ->
-  let s1_auth_user_sid =
-    Db_actions.DB_Action.Session.get_auth_user_sid ~__context ~self:s1
-  in
-  let s2_auth_user_sid =
-    Db_actions.DB_Action.Session.get_auth_user_sid ~__context ~self:s2
-  in
-  s1_auth_user_sid = s2_auth_user_sid
+  let open Db_actions.DB_Action.Session in
+  let s1_auth_user_sid = get_auth_user_sid ~__context ~self:s1 in
+  let s2_auth_user_sid = get_auth_user_sid ~__context ~self:s2 in
+  match s1_auth_user_sid = s2_auth_user_sid with
+  | false ->
+      false
+  | true when s1_auth_user_sid <> "" ->
+      true
+  | _ ->
+      (* Only local superuser and client-cert sessions have no sid, and a
+         session is exactly one of them. *)
+      let f = get_is_local_superuser ~__context in
+      f ~self:s1 = f ~self:s2
 
 let assert_op_valid ?(ok_if_no_session_in_context = false) ~__context task_id =
   let@ __context = Context.with_tracing ~__context __FUNCTION__ in
diff --git a/ocaml/xapi/xapi_http.ml b/ocaml/xapi/xapi_http.ml
index 50d4767140aa..bf28e4965b6d 100644
--- a/ocaml/xapi/xapi_http.ml
+++ b/ocaml/xapi/xapi_http.ml
@@ -100,8 +100,8 @@ let create_session_for_client_cert req s =
 
 let assert_credentials_ok realm ?(http_action = realm) ?(fn = Rbac.nofn)
     (req : Request.t) ic =
+  let task_id = ref_param_of_req req "task_id" in
   let rbac_raise permission msg exc =
-    let task_id = ref_param_of_req req "task_id" in
     ( match task_id with
     | None ->
         ()
@@ -115,6 +115,16 @@ let assert_credentials_ok realm ?(http_action = realm) ?(fn = Rbac.nofn)
     raise exc
   in
   let rbac_check session_id =
+    ( match task_id with
+    | None ->
+        ()
+    | Some task_id ->
+        if not (Server_helpers.can_own_task ~session_id task_id) then (
+          error "Refusing the request: task %s is not owned by the caller"
+            (Ref.string_of task_id) ;
+          raise Http.Forbidden
+        )
+    ) ;
     let rbac_task_desc = "handler" in
     let http_permission = Datamodel.rbac_http_permission_prefix ^ http_action in
     try
@@ -263,6 +273,8 @@ let with_context ?(dummy = false) label (req : Request.t) (s : Unix.file_descr)
             Xapi_session.consider_touching_session inet_rpc session_id () ;
           f __context
         in
+        (* The caller-supplied task is the one [f] runs under and reports into.
+           It must therefore belong to the caller. *)
         match task_id with
         | None ->
             Server_helpers.exec_with_new_task ?subtask_of ~session_id
@@ -270,9 +282,15 @@ let with_context ?(dummy = false) label (req : Request.t) (s : Unix.file_descr)
               ~origin:(Context.Http (req, s))
               label login_perform_logout
         | Some task_id ->
-            Server_helpers.exec_with_forwarded_task ~session_id
-              ~origin:(Context.Http (req, s))
-              task_id login_perform_logout
+            if Server_helpers.can_own_task ~session_id task_id then
+              Server_helpers.exec_with_forwarded_task ~session_id
+                ~origin:(Context.Http (req, s))
+                task_id login_perform_logout
+            else (
+              warn "Refusing the request: task %s is not owned by the caller"
+                (Ref.string_of task_id) ;
+              raise Http.Forbidden
+            )
       )
       (fun () ->
         if must_logout then
@@ -281,20 +299,9 @@ let with_context ?(dummy = false) label (req : Request.t) (s : Unix.file_descr)
             session_id
       )
   with Http.Unauthorised _ as e ->
-    let fail __context =
-      TaskHelper.failed ~__context
-        (Api_errors.Server_error (Api_errors.session_authentication_failed, []))
-    in
     debug
       "No authentication provided to http handler: returning 401 unauthorised" ;
-    (* Fail the task *)
-    ( match task_id with
-    | None ->
-        Server_helpers.exec_with_new_task ~task_in_database:(not dummy) label
-          fail
-    | Some task_id ->
-        Server_helpers.exec_with_forwarded_task task_id fail
-    ) ;
+    (* Do nothing here as authentication failed already. *)
     req.Request.close <- true ;
     raise e
 
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430077: Unit tests for task ownership check before setting the
 task failed

This is CVE-2026-119779, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/tests/suite_alcotest.ml b/ocaml/tests/suite_alcotest.ml
index 25c2130caabe..f4c66b188748 100644
--- a/ocaml/tests/suite_alcotest.ml
+++ b/ocaml/tests/suite_alcotest.ml
@@ -77,4 +77,5 @@ let () =
     @ Test_vm_protected_keys.tests
     @ Test_vm_protected_fields.tests
     @ Test_network_protected_keys.tests
+    @ Test_task_ownership.tests
     )
diff --git a/ocaml/tests/test_task_ownership.ml b/ocaml/tests/test_task_ownership.ml
new file mode 100644
index 000000000000..be816dd5bc71
--- /dev/null
+++ b/ocaml/tests/test_task_ownership.ml
@@ -0,0 +1,419 @@
+(*
+ * Copyright (C) Cloud Software Group, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+let rbac_denied = Api_errors.rbac_permission_denied
+
+let http_action = "put_import"
+
+let http_permission = Datamodel.rbac_http_permission_prefix ^ http_action
+
+let destroy_any_permission = Datamodel.Task.extra_permission_task_destroy_any
+
+let make_session ~__context ?(rbac_permissions = []) ~auth_user_sid () =
+  Test_common.make_session ~__context ~is_local_superuser:false ~auth_user_sid
+    ~rbac_permissions ()
+
+let make_task ~__context ~session_id label =
+  let self = Ref.make () in
+  Db.Task.create ~__context ~ref:self ~uuid:(Test_common.make_uuid ())
+    ~name_label:label ~name_description:"" ~created:API.Date.epoch
+    ~finished:API.Date.epoch ~status:`pending ~session:session_id
+    ~resident_on:!Xapi_globs.localhost_ref ~progress:0. ~_type:"<none/>"
+    ~result:"" ~error_info:[] ~allowed_operations:[] ~current_operations:[]
+    ~subtask_of:Ref.null ~other_config:[] ~stunnelpid:(-1L) ~forwarded:false
+    ~forwarded_to:Ref.null ~externalpid:(-1L) ~backtrace:"" ;
+  self
+
+let request ?task_id ~session_id () =
+  let query =
+    ("session_id", Ref.string_of session_id)
+    ::
+    ( match task_id with
+    | None ->
+        []
+    | Some task_id ->
+        [("task_id", Ref.string_of task_id)]
+    )
+  in
+  Http.Request.make ~user_agent:"test_task_ownership" ~query Http.Put "/import"
+
+let with_remote_fd f =
+  (* When the [ic] parameter of [assert_credentials_ok] is a UNIX socket, it is
+     trusted always. There will be no check against the request. So a TCP socket
+     is created here to simulate requests from network. *)
+  let fd = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
+  Xapi_stdext_pervasives.Pervasiveext.finally
+    (fun () -> f fd)
+    (fun () -> Unix.close fd)
+
+let assert_credentials_ok ?task_id ?fn ~session_id () =
+  with_remote_fd (fun fd ->
+      Xapi_http.assert_credentials_ok "test_realm" ~http_action ?fn
+        (request ?task_id ~session_id ())
+        fd
+  )
+
+let expect_forbidden msg f =
+  match f () with
+  | () ->
+      Alcotest.failf "%s: expected Http.Forbidden but the call succeeded" msg
+  | exception Http.Forbidden ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected Http.Forbidden but got %s" msg
+        (ExnHelper.string_of_exn e)
+
+let expect_rbac_denied msg f =
+  match f () with
+  | () ->
+      Alcotest.failf "%s: expected %s but the call succeeded" msg
+        Api_errors.rbac_permission_denied
+  | exception Api_errors.Server_error (code, _)
+    when code = Api_errors.rbac_permission_denied ->
+      ()
+  | exception e ->
+      Alcotest.failf "%s: expected %s but got %s" msg
+        Api_errors.rbac_permission_denied
+        (ExnHelper.string_of_exn e)
+
+let check_task_status ~__context ~task ~expected msg =
+  Alcotest.(check string)
+    (msg ^ ": task status")
+    (TaskHelper.status_to_string expected)
+    (TaskHelper.status_to_string (Db.Task.get_status ~__context ~self:task))
+
+let check_task_untouched ~__context ~task msg =
+  check_task_status ~__context ~task ~expected:`pending msg ;
+  Alcotest.(check (list string))
+    (msg ^ ": task error_info")
+    []
+    (Db.Task.get_error_info ~__context ~self:task)
+
+let check_task_failed ~__context ~task msg =
+  check_task_status ~__context ~task ~expected:`failure msg ;
+  match Db.Task.get_error_info ~__context ~self:task with
+  | code :: _ ->
+      Alcotest.(check string) (msg ^ ": task error code") rbac_denied code
+  | [] ->
+      Alcotest.failf "%s: nothing recorded in the error_info of the task" msg
+
+let test_fails_own_task () =
+  let __context = Test_common.make_test_database () in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  let task = make_task ~__context ~session_id "own task" in
+  expect_forbidden "own task" (fun () ->
+      assert_credentials_ok ~session_id ~task_id:task ()
+  ) ;
+  check_task_failed ~__context ~task "own task"
+
+let test_fails_task_of_same_user () =
+  let __context = Test_common.make_test_database () in
+  let owner = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  let task = make_task ~__context ~session_id:owner "task of the same user" in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  expect_forbidden "task of the same user" (fun () ->
+      assert_credentials_ok ~session_id ~task_id:task ()
+  ) ;
+  check_task_failed ~__context ~task "task of the same user"
+
+let test_denies_task_of_other_user () =
+  let __context = Test_common.make_test_database () in
+  let victim = make_session ~__context ~auth_user_sid:"S-1-victim" () in
+  let task = make_task ~__context ~session_id:victim "task of the victim" in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-attacker" () in
+  expect_forbidden "task of another user" (fun () ->
+      assert_credentials_ok ~session_id ~task_id:task ()
+  ) ;
+  check_task_untouched ~__context ~task "task of another user"
+
+let test_denies_unknown_task () =
+  let __context = Test_common.make_test_database () in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  let task_id =
+    Ref.of_string "OpaqueRef:12345678-1234-1234-1234-123456789012"
+  in
+  expect_forbidden "unknown task" (fun () ->
+      assert_credentials_ok ~session_id ~task_id ()
+  )
+
+let test_allows_permitted_caller () =
+  let __context = Test_common.make_test_database () in
+  let session_id =
+    Test_common.make_session ~__context ~is_local_superuser:true ()
+  in
+  let task = make_task ~__context ~session_id "own task" in
+  let called = ref false in
+  ( match
+      assert_credentials_ok ~session_id ~task_id:task
+        ~fn:(fun () -> called := true)
+        ()
+    with
+  | () ->
+      ()
+  | exception e ->
+      Alcotest.failf "permitted caller: expected success but got %s"
+        (ExnHelper.string_of_exn e)
+  ) ;
+  Alcotest.(check bool) "permitted caller: handler called" true !called ;
+  check_task_untouched ~__context ~task "permitted caller"
+
+let test_denies_others_task_before_handler () =
+  let __context = Test_common.make_test_database () in
+  let victim = make_session ~__context ~auth_user_sid:"S-1-victim" () in
+  let task = make_task ~__context ~session_id:victim "task of the victim" in
+  let session_id =
+    make_session ~__context ~auth_user_sid:"S-1-attacker"
+      ~rbac_permissions:[http_permission] ()
+  in
+  let called = ref false in
+  expect_forbidden "permitted caller, task of another user" (fun () ->
+      assert_credentials_ok ~session_id ~task_id:task
+        ~fn:(fun () -> called := true)
+        ()
+  ) ;
+  Alcotest.(check bool)
+    "permitted caller, task of another user: handler not called" false !called ;
+  check_task_untouched ~__context ~task "permitted caller, task of another user"
+
+let test_allows_others_task_for_destroy_any_holder () =
+  let __context = Test_common.make_test_database () in
+  let stranded = make_session ~__context ~auth_user_sid:"S-1-stranded" () in
+  let task =
+    make_task ~__context ~session_id:stranded "task of a stranded user"
+  in
+  let session_id =
+    make_session ~__context ~auth_user_sid:"S-1-operator"
+      ~rbac_permissions:[destroy_any_permission; http_permission]
+      ()
+  in
+  let called = ref false in
+  ( match
+      assert_credentials_ok ~session_id ~task_id:task
+        ~fn:(fun () -> called := true)
+        ()
+    with
+  | () ->
+      ()
+  | exception e ->
+      Alcotest.failf "holder of task.destroy/any: expected success but got %s"
+        (ExnHelper.string_of_exn e)
+  ) ;
+  Alcotest.(check bool)
+    "holder of task.destroy/any: handler called" true !called ;
+  check_task_untouched ~__context ~task "holder of task.destroy/any"
+
+let test_fails_others_task_for_destroy_any_holder () =
+  let __context = Test_common.make_test_database () in
+  let stranded = make_session ~__context ~auth_user_sid:"S-1-stranded" () in
+  let task =
+    make_task ~__context ~session_id:stranded "task of a stranded user"
+  in
+  let session_id =
+    make_session ~__context ~auth_user_sid:"S-1-operator"
+      ~rbac_permissions:[destroy_any_permission] ()
+  in
+  expect_forbidden "holder of task.destroy/any, RBAC-denied" (fun () ->
+      assert_credentials_ok ~session_id ~task_id:task ()
+  ) ;
+  check_task_failed ~__context ~task "holder of task.destroy/any, RBAC-denied"
+
+let check_can_own_task ?session_id ~expected ~task msg =
+  Alcotest.(check bool)
+    (msg ^ ": can_own_task") expected
+    (Server_helpers.can_own_task ?session_id task)
+
+let test_own_task_of_same_user () =
+  let __context = Test_common.make_test_database () in
+  let owner = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  let task = make_task ~__context ~session_id:owner "task of the same user" in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  check_can_own_task ~session_id ~expected:true ~task "task of the same user"
+
+let test_not_own_task_of_other_user () =
+  let __context = Test_common.make_test_database () in
+  let victim = make_session ~__context ~auth_user_sid:"S-1-victim" () in
+  let task = make_task ~__context ~session_id:victim "task of the victim" in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-attacker" () in
+  check_can_own_task ~session_id ~expected:false ~task "task of another user"
+
+let test_not_own_task_without_session () =
+  (* The Http.Unauthorised path of Xapi_http.with_context has no session at all. *)
+  let __context = Test_common.make_test_database () in
+  let victim = make_session ~__context ~auth_user_sid:"S-1-victim" () in
+  let task = make_task ~__context ~session_id:victim "task of the victim" in
+  check_can_own_task ~expected:false ~task "no session" ;
+  check_task_untouched ~__context ~task "no session"
+
+let test_not_own_task_when_unknown () =
+  let __context = Test_common.make_test_database () in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  let task = Ref.of_string "OpaqueRef:12345678-1234-1234-1234-123456789012" in
+  check_can_own_task ~session_id ~expected:false ~task "unknown task"
+
+let test_own_task_of_local_superuser () =
+  let __context = Test_common.make_test_database () in
+  let stranded = make_session ~__context ~auth_user_sid:"S-1-stranded" () in
+  let task =
+    make_task ~__context ~session_id:stranded "task of a stranded user"
+  in
+  let session_id =
+    Test_common.make_session ~__context ~is_local_superuser:true ()
+  in
+  check_can_own_task ~session_id ~expected:true ~task "local superuser"
+
+let test_own_task_of_destroy_any_holder () =
+  let __context = Test_common.make_test_database () in
+  let stranded = make_session ~__context ~auth_user_sid:"S-1-stranded" () in
+  let task =
+    make_task ~__context ~session_id:stranded "task of a stranded user"
+  in
+  let session_id =
+    make_session ~__context ~auth_user_sid:"S-1-operator"
+      ~rbac_permissions:[destroy_any_permission] ()
+  in
+  check_can_own_task ~session_id ~expected:true ~task
+    "holder of task.destroy/any"
+
+let request_with_task_header ?task ~session_id () =
+  let req = request ~session_id () in
+  match task with
+  | None ->
+      req
+  | Some task ->
+      {req with Http.Request.task= Some (Ref.string_of task)}
+
+let dispatch ?task ?(supports_async = true) ~session_id () =
+  let ran = ref false in
+  let (_ : Rpc.response) =
+    Server_helpers.do_dispatch ~session_id supports_async "Test.call"
+      (fun ~__context:_ -> ran := true)
+      (fun () -> Rpc.Null)
+      None
+      (request_with_task_header ?task ~session_id ())
+      "test_do_dispatch" `Sync true
+  in
+  !ran
+
+let check_dispatch_ran ~expected ~session_id ?task ?supports_async msg =
+  Alcotest.(check bool)
+    (msg ^ ": operation ran") expected
+    (dispatch ?task ?supports_async ~session_id ())
+
+let test_dispatch_denies_task_of_other_user () =
+  let __context = Test_common.make_test_database () in
+  let victim = make_session ~__context ~auth_user_sid:"S-1-victim" () in
+  let task = make_task ~__context ~session_id:victim "task of the victim" in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-attacker" () in
+  expect_rbac_denied "task-id header naming another user's task" (fun () ->
+      ignore (dispatch ~task ~session_id ())
+  ) ;
+  check_task_untouched ~__context ~task "task-id header, another user"
+
+let test_dispatch_allows_own_task () =
+  let __context = Test_common.make_test_database () in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  let task = make_task ~__context ~session_id "task of the caller" in
+  check_dispatch_ran ~expected:true ~session_id ~task
+    "task-id header naming the caller's own task"
+
+let test_dispatch_allows_local_superuser () =
+  let __context = Test_common.make_test_database () in
+  let originator = make_session ~__context ~auth_user_sid:"S-1-originator" () in
+  let task = make_task ~__context ~session_id:originator "forwarded task" in
+  let session_id =
+    Test_common.make_session ~__context ~pool:true ~is_local_superuser:true ()
+  in
+  check_dispatch_ran ~expected:true ~session_id ~task
+    "task-id header on a forwarded call"
+
+let test_dispatch_allows_without_task_header () =
+  let __context = Test_common.make_test_database () in
+  let session_id = make_session ~__context ~auth_user_sid:"S-1-caller" () in
+  check_dispatch_ran ~expected:true ~session_id ~supports_async:false
+    "no task-id header"
+
+let tests =
+  [
+    ( "Xapi_http.assert_credentials_ok: RBAC-denied task"
+    , [
+        ("fails the task of the caller", `Quick, test_fails_own_task)
+      ; ("fails the task of the same user", `Quick, test_fails_task_of_same_user)
+      ; ( "leaves the task of another user untouched"
+        , `Quick
+        , test_denies_task_of_other_user
+        )
+      ; ("rejects an unknown task", `Quick, test_denies_unknown_task)
+      ; ( "leaves the task of a permitted caller untouched"
+        , `Quick
+        , test_allows_permitted_caller
+        )
+      ; ( "refuses the task of another user before running the handler"
+        , `Quick
+        , test_denies_others_task_before_handler
+        )
+      ; ( "runs the handler when a holder of task.destroy/any supplies the \
+           task of another user"
+        , `Quick
+        , test_allows_others_task_for_destroy_any_holder
+        )
+      ; ( "fails the task of another user when a holder of task.destroy/any is \
+           RBAC-denied"
+        , `Quick
+        , test_fails_others_task_for_destroy_any_holder
+        )
+      ]
+    )
+  ; ( "Server_helpers.can_own_task"
+    , [
+        ("owns the task of the same user", `Quick, test_own_task_of_same_user)
+      ; ( "does not own the task of another user"
+        , `Quick
+        , test_not_own_task_of_other_user
+        )
+      ; ( "does not own any task without a session"
+        , `Quick
+        , test_not_own_task_without_session
+        )
+      ; ("does not own an unknown task", `Quick, test_not_own_task_when_unknown)
+      ; ( "allows a local superuser to own the task of another user"
+        , `Quick
+        , test_own_task_of_local_superuser
+        )
+      ; ( "allows a holder of task.destroy/any to own the task of another user"
+        , `Quick
+        , test_own_task_of_destroy_any_holder
+        )
+      ]
+    )
+  ; ( "Server_helpers.do_dispatch: the task-id header"
+    , [
+        ( "refuses a task named by the header that belongs to another user"
+        , `Quick
+        , test_dispatch_denies_task_of_other_user
+        )
+      ; ( "runs when the header names the caller's own task"
+        , `Quick
+        , test_dispatch_allows_own_task
+        )
+      ; ( "runs when a forwarded call names the originator's task"
+        , `Quick
+        , test_dispatch_allows_local_superuser
+        )
+      ; ( "runs when no task is named by the request"
+        , `Quick
+        , test_dispatch_allows_without_task_header
+        )
+      ]
+    )
+  ]
From: Andrii Sultanov <andriy.sultanov@vates.tech>
Subject: CA-430077: Unit tests for client certificate sessions and root tasks

A client certificate session has an empty auth_user_sid, the same as a
root session. Check that it still can't own a task of root, neither via
Server_helpers.can_own_task nor via the task-id header in
Server_helpers.do_dispatch.

This is CVE-2026-119779, part of XSA-530.

Signed-off-by: Andrii Sultanov <andriy.sultanov@vates.tech>
Reviewed-by: Ming Lu <ming.lu@citrix.com>

diff --git a/ocaml/tests/test_task_ownership.ml b/ocaml/tests/test_task_ownership.ml
index be816dd5bc71..c81be0b50e04 100644
--- a/ocaml/tests/test_task_ownership.ml
+++ b/ocaml/tests/test_task_ownership.ml
@@ -24,6 +24,10 @@ let make_session ~__context ?(rbac_permissions = []) ~auth_user_sid () =
   Test_common.make_session ~__context ~is_local_superuser:false ~auth_user_sid
     ~rbac_permissions ()
 
+let make_client_cert_session ~__context =
+  Test_common.make_session ~__context ~is_local_superuser:false
+    ~auth_user_sid:"" ~client_certificate:true ()
+
 let make_task ~__context ~session_id label =
   let self = Ref.make () in
   Db.Task.create ~__context ~ref:self ~uuid:(Test_common.make_uuid ())
@@ -247,6 +251,14 @@ let test_not_own_task_of_other_user () =
   let session_id = make_session ~__context ~auth_user_sid:"S-1-attacker" () in
   check_can_own_task ~session_id ~expected:false ~task "task of another user"
 
+let test_client_cert_does_not_own_root_task () =
+  let __context = Test_common.make_test_database () in
+  let root = Test_common.make_session ~__context ~is_local_superuser:true () in
+  let task = make_task ~__context ~session_id:root "task of the root" in
+  let session_id = make_client_cert_session ~__context in
+  check_can_own_task ~session_id ~expected:false ~task
+    "client-cert session and root task"
+
 let test_not_own_task_without_session () =
   (* The Http.Unauthorised path of Xapi_http.with_context has no session at all. *)
   let __context = Test_common.make_test_database () in
@@ -343,6 +355,17 @@ let test_dispatch_allows_without_task_header () =
   check_dispatch_ran ~expected:true ~session_id ~supports_async:false
     "no task-id header"
 
+let test_dispatch_denies_client_cert_with_root_task () =
+  let __context = Test_common.make_test_database () in
+  let root = Test_common.make_session ~__context ~is_local_superuser:true () in
+  let task = make_task ~__context ~session_id:root "task of the root" in
+  let session_id = make_client_cert_session ~__context in
+  expect_rbac_denied
+    "task-id header from a client-cert session naming a root's task" (fun () ->
+      ignore (dispatch ~task ~session_id ())
+  ) ;
+  check_task_untouched ~__context ~task "task-id header, client-cert session"
+
 let tests =
   [
     ( "Xapi_http.assert_credentials_ok: RBAC-denied task"
@@ -394,6 +417,10 @@ let tests =
         , `Quick
         , test_own_task_of_destroy_any_holder
         )
+      ; ( "does not own a root task from a client-cert session"
+        , `Quick
+        , test_client_cert_does_not_own_root_task
+        )
       ]
     )
   ; ( "Server_helpers.do_dispatch: the task-id header"
@@ -414,6 +441,10 @@ let tests =
         , `Quick
         , test_dispatch_allows_without_task_header
         )
+      ; ( "refuses a root task named by a client-cert session"
+        , `Quick
+        , test_dispatch_denies_client_cert_with_root_task
+        )
       ]
     )
   ]
From: Ming Lu <ming.lu@citrix.com>
Subject: CA-430810: Newline in repository_proxy_url injects yum/dnf .repo
 directives

Add sanity check in the URLs, proxy username and password configured for YUM/DNF.

This is CVE-2026-119780, part of XSA-530.

Signed-off-by: Ming Lu <ming.lu@citrix.com>
Reviewed-by: Andrii Sultanov <andriy.sultanov@vates.tech>

diff --git a/ocaml/tests/test_repository_helpers.ml b/ocaml/tests/test_repository_helpers.ml
index 8ef4ba31445f..ad0f7d856946 100644
--- a/ocaml/tests/test_repository_helpers.ml
+++ b/ocaml/tests/test_repository_helpers.ml
@@ -250,6 +250,96 @@ module AssertUrlIsValid = Generic.MakeStateless (struct
       ; (("https://a.b.d.com//", ["c.com"; "d.com"]), Ok ())
       ; (("https://a.b.d.com/a/b", ["c.com"; "d.com"]), Ok ())
       ; (("https://a.b.d.com/a/b/", ["c.com"; "d.com"]), Ok ())
+      ; (* control characters are rejected wherever they appear *)
+        ( ("http://a.b.c.com/a\n/b", ["c.com"])
+        , Error
+            Api_errors.(
+              Server_error (invalid_base_url, ["http://a.b.c.com/a\n/b"])
+            )
+        )
+      ; ( ("http://a.b.c.com\r\nX-Injected: 1", ["c.com"])
+        , Error
+            Api_errors.(
+              Server_error
+                (invalid_base_url, ["http://a.b.c.com\r\nX-Injected: 1"])
+            )
+        )
+      ; ( ("http://a.b.c\000.com", ["c.com"])
+        , Error
+            Api_errors.(
+              Server_error (invalid_base_url, ["http://a.b.c\000.com"])
+            )
+        )
+      ; ( ("http://a.b.c.com/\127", ["c.com"])
+        , Error
+            Api_errors.(
+              Server_error (invalid_base_url, ["http://a.b.c.com/\127"])
+            )
+        )
+      ; ( ("\thttp://a.b.c.com", ["c.com"])
+        , Error
+            Api_errors.(Server_error (invalid_base_url, ["\thttp://a.b.c.com"]))
+        )
+      ]
+end)
+
+module AssertRemotePoolUrlIsValid = Generic.MakeStateless (struct
+  module Io = struct
+    type input_t = string
+
+    type output_t = (unit, exn) result
+
+    let string_of_input_t = Fmt.(str "%a" Dump.string)
+
+    let string_of_output_t =
+      Fmt.(str "%a" Dump.(result ~ok:(any "()") ~error:exn))
+  end
+
+  let transform url =
+    try Ok (assert_remote_pool_url_is_valid ~url) with e -> Error e
+
+  let invalid url = Error Api_errors.(Server_error (invalid_base_url, [url]))
+
+  let tests =
+    `QuickAndAutoDocumented
+      [
+        ("https://192.168.0.2/repository/enabled", Ok ())
+      ; ("https://[::1]/repository/enabled", Ok ())
+      ; (* wrong scheme, host or path *)
+        ( "http://192.168.0.2/repository/enabled"
+        , invalid "http://192.168.0.2/repository/enabled"
+        )
+      ; ( "https://a.b.c.com/repository/enabled"
+        , invalid "https://a.b.c.com/repository/enabled"
+        )
+      ; ( "https://192.168.0.2/repository"
+        , invalid "https://192.168.0.2/repository"
+        )
+      ; (* a newline terminates Uri.path, so the shape check on its own would
+           accept these and the trailing lines would reach the .repo file *)
+        ( "https://192.168.0.2/repository/enabled\n\
+           [evil]\n\
+           baseurl=http://attacker/"
+        , invalid
+            "https://192.168.0.2/repository/enabled\n\
+             [evil]\n\
+             baseurl=http://attacker/"
+        )
+      ; ( "https://192.168.0.2/repository/enabled\nproxy=http://attacker:3128"
+        , invalid
+            "https://192.168.0.2/repository/enabled\nproxy=http://attacker:3128"
+        )
+      ; (* other control characters, which the shape check already rejected but
+           which must keep reporting the same error *)
+        ( "https://192.168.0.2/repository/enabled\r\nX-Injected: 1"
+        , invalid "https://192.168.0.2/repository/enabled\r\nX-Injected: 1"
+        )
+      ; ( "https://192.168.0.2\000/repository/enabled"
+        , invalid "https://192.168.0.2\000/repository/enabled"
+        )
+      ; ( "\thttps://192.168.0.2/repository/enabled"
+        , invalid "\thttps://192.168.0.2/repository/enabled"
+        )
       ]
 end)
 
@@ -5576,6 +5666,7 @@ let tests =
     [
       ("update_of_json", UpdateOfJsonTest.tests)
     ; ("assert_url_is_valid", AssertUrlIsValid.tests)
+    ; ("assert_remote_pool_url_is_valid", AssertRemotePoolUrlIsValid.tests)
     ; ("assert_url_is_not_blocked", AssertUrlIsNotBlocked.tests)
     ; ("write_yum_config", WriteYumConfig.tests)
     ; ("eval_guidance_for_one_update", EvalGuidanceForOneUpdate.tests)
diff --git a/ocaml/xapi/repository.ml b/ocaml/xapi/repository.ml
index 6c655de59fa9..cdd060404b08 100644
--- a/ocaml/xapi/repository.ml
+++ b/ocaml/xapi/repository.ml
@@ -140,11 +140,17 @@ let get_proxy_params ~__context =
   match (url, username, password_ref) with
   | url', username', password_ref'
     when url' <> "" && username' <> "" && password_ref' <> Ref.null ->
+      let password = Db.Secret.get_value ~__context ~self:password_ref' in
+      (* The secret value may change after being configured. Re-check it again. *)
+      if has_control_character password then (
+        error
+          "The password of the repository proxy contains control character(s)" ;
+        raise Api_errors.(Server_error (invalid_repository_proxy_credential, []))
+      ) ;
       [
         Printf.sprintf "proxy=%s" url'
       ; Printf.sprintf "proxy_username=%s" username'
-      ; Printf.sprintf "proxy_password=%s"
-          (Db.Secret.get_value ~__context ~self:password_ref')
+      ; Printf.sprintf "proxy_password=%s" password
       ]
   | url', "", _ when url' <> "" ->
       [Printf.sprintf "proxy=%s" url']
diff --git a/ocaml/xapi/repository_helpers.ml b/ocaml/xapi/repository_helpers.ml
index 13d0eb94770f..5d6bc65558c8 100644
--- a/ocaml/xapi/repository_helpers.ml
+++ b/ocaml/xapi/repository_helpers.ml
@@ -164,7 +164,21 @@ module DomainNameIncludeIP = struct
     )
 end
 
+let has_control_character s =
+  let is_control_character c =
+    let code = Char.code c in
+    code < 0x20 || code = 0x7f
+  in
+  String.exists is_control_character s
+
+let assert_no_control_chars ~url ~url_error =
+  if has_control_character url then (
+    error "Invalid url: it contains control character(s)" ;
+    raise Api_errors.(Server_error (url_error, [url]))
+  )
+
 let assert_url_is_valid ~url =
+  assert_no_control_chars ~url ~url_error:Api_errors.invalid_base_url ;
   try
     let uri = Uri.of_string url in
     match Uri.(scheme uri, host uri) with
@@ -265,6 +279,7 @@ let get_remote_pool_coordinator_ip url =
       raise Api_errors.(Server_error (invalid_base_url, [url]))
 
 let assert_remote_pool_url_is_valid ~url =
+  assert_no_control_chars ~url ~url_error:Api_errors.invalid_base_url ;
   ignore (get_remote_pool_coordinator_ip url : string)
 
 let with_pool_repositories f =
diff --git a/ocaml/xapi/xapi_pool.ml b/ocaml/xapi/xapi_pool.ml
index 63f208b98c41..de1959246996 100644
--- a/ocaml/xapi/xapi_pool.ml
+++ b/ocaml/xapi/xapi_pool.ml
@@ -4317,13 +4317,18 @@ let configure_repository_proxy ~__context ~self ~url ~username ~password =
       error "missing password of the repository proxy with a username specified" ;
       raise Api_errors.(Server_error (invalid_repository_proxy_credential, []))
   | u, p when u <> "" && p <> "" ->
-      if String.contains u '\n' || String.contains p '\n' then (
+      if
+        Repository_helpers.has_control_character u
+        || Repository_helpers.has_control_character p
+      then (
         error "getting invalid username/password of the repository proxy" ;
         raise Api_errors.(Server_error (invalid_repository_proxy_credential, []))
       )
   | _ ->
       ()
   ) ;
+  Repository_helpers.assert_no_control_chars ~url
+    ~url_error:Api_errors.invalid_repository_proxy_url ;
   let old_secret_ref = Db.Pool.get_repository_proxy_password ~__context ~self in
   let secret_ref =
     if password = "" then