Skip to content

Commit

Permalink
fix: more secure handling of date in xva
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Jan 29, 2024
1 parent cddb316 commit 01d16a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 7 additions & 3 deletions @xen-orchestra/xva-generator/_toOvaXml.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ function escape(string) {
if (typeof string === 'number') {
return string
}
if (string.startsWith('<dateTime.iso8601>')) {
return string
}
const map = {
'>': '&gt;',
'<': '&lt;',
Expand All @@ -21,12 +18,19 @@ function escape(string) {
})
}

function formatDate(d) {
return d.toISOString().replaceAll('-', '').replace('.000Z', 'Z')
}

export default function toOvaxml(obj) {
if (Array.isArray(obj)) {
return `<value><array><data>${obj.map(val => toOvaxml(val)).join('')}</data></array></value>`
}

if (typeof obj === 'object') {
if (obj instanceof Date) {
return `<value><dateTime.iso8601>${escape(formatDate(obj))}</dateTime.iso8601></value>`
}
return `<value><struct>${Object.entries(obj)
.map(([key, value]) => `<member><name>${escape(key)}</name>${toOvaxml(value)}</member>`)
.join('')}</struct></value>`
Expand Down
10 changes: 4 additions & 6 deletions @xen-orchestra/xva-generator/templates/vm.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

export const DEFAULT_VM = {
class: 'VM',
id: null,
snapshot:
{
snapshot: {
actions_after_crash: 'restart',
actions_after_reboot: 'restart',
actions_after_shutdown: 'destroy',
Expand Down Expand Up @@ -85,7 +83,7 @@ export const DEFAULT_VM = {
snapshot_info: {},
snapshot_metadata: '',
snapshot_of: 'OpaqueRef:NULL',
snapshot_time: '<dateTime.iso8601>19700101T00:00:00Z</dateTime.iso8601>',
snapshot_time: new Date(0),
snapshots: [],
start_delay: 0,
// suspend_VDI:'OpaqueRef:NULL',
Expand All @@ -104,5 +102,5 @@ export const DEFAULT_VM = {
VTPMs: [],
VUSBs: [],
xenstore_data: {},
}
}
},
}

0 comments on commit 01d16a9

Please sign in to comment.