Skip to content

Commit e187b02

Browse files
authored
fix: Also set inValidNode when CSP starts with comment (#27376)
Addresses #26443 (comment) after #27176 was merged. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - I did this in #27176, same change message. - [x] Added/updated automated tests - [x] Manual QA for all new/changed functionality
1 parent 4a1e534 commit e187b02

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

server/fleet/windows_mdm.go

+11
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (m *MDMWindowsConfigProfile) ValidateUserProvided() error {
7979
// structure (Target>Item>LocURI) so we don't need to track all the tags.
8080
var inValidNode bool
8181
var inLocURI bool
82+
var inComment bool
8283

8384
for {
8485
tok, err := dec.Token()
@@ -97,9 +98,19 @@ func (m *MDMWindowsConfigProfile) ValidateUserProvided() error {
9798
return errors.New("The file should include valid XML: processing instructions are not allowed.")
9899

99100
case xml.Comment:
101+
inComment = true
100102
continue
101103

102104
case xml.StartElement:
105+
// Top-level comments should be followed by <Replace> or <Add> elements
106+
if inComment {
107+
if !inValidNode && t.Name.Local != "Replace" && t.Name.Local != "Add" {
108+
return errors.New("Windows configuration profiles can only have <Replace> or <Add> top level elements after comments")
109+
}
110+
inValidNode = true
111+
inComment = false
112+
}
113+
103114
switch t.Name.Local {
104115
case "Replace", "Add":
105116
inValidNode = true

server/fleet/windows_mdm_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,23 @@ func TestValidateUserProvided(t *testing.T) {
422422
},
423423
wantErr: "",
424424
},
425+
{
426+
name: "XML with top level comment followed by invalid element",
427+
profile: MDMWindowsConfigProfile{
428+
SyncML: []byte(`
429+
<!-- this is a comment -->
430+
<!-- this is another comment -->
431+
<LocURI>Custom/URI</LocURI>
432+
<Replace>
433+
<!-- this is a comment inside replace -->
434+
<Target>
435+
<LocURI>Custom/URI</LocURI>
436+
</Target>
437+
</Replace>
438+
`),
439+
},
440+
wantErr: "Windows configuration profiles can only have <Replace> or <Add> top level elements after comments",
441+
},
425442
{
426443
name: "XML with nested root element in data",
427444
profile: MDMWindowsConfigProfile{

0 commit comments

Comments
 (0)