Skip to content

Commit

Permalink
Merge pull request #3007 from SCADA-LTS/fix/#2985_Prevent_XSS_for_RES…
Browse files Browse the repository at this point in the history
…T_API_by_escape_String_content2

#2985 Prevent XSS for REST API by escape String content:
  • Loading branch information
Limraj authored Nov 27, 2024
2 parents a0030c1 + c50a0a5 commit bda0e41
Show file tree
Hide file tree
Showing 75 changed files with 384 additions and 212 deletions.
21 changes: 14 additions & 7 deletions scadalts-ui/src/components/datasources/DataPointCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<h1>
<span v-if="creator"> Create </span>
<span v-else> Update </span>
<span>
{{ title }}
<span v-html="title">
</span>
</h1>
</v-col>
Expand All @@ -23,15 +22,15 @@
<v-col cols="12" :sm="6">
<v-text-field
autofocus
v-model="datapoint.name"
v-model="datapoint.tempName"
label="Data Point Name"
:rules="[ruleNotNull]"
required
></v-text-field>
</v-col>
<v-col cols="6" :sm="4">
<v-text-field
v-model="datapoint.xid"
v-model="datapoint.tempXid"
label="Data Point Export ID"
@input="checkXidUnique"
:rules="[ruleNotNull, ruleXidUnique]"
Expand All @@ -47,7 +46,7 @@
</v-col>
<v-col cols="12">
<v-text-field
v-model="datapoint.description"
v-model="datapoint.tempDescription"
label="Description"
></v-text-field>
</v-col>
Expand Down Expand Up @@ -99,6 +98,9 @@ export default {
async mounted(){
this.initialState = JSON.parse(JSON.stringify(this.datapoint));
this.datapoint.tempName = this.datapoint.name;
this.datapoint.tempXid = this.datapoint.xid;
this.datapoint.tempDescription = this.datapoint.description;
},
data() {
Expand All @@ -107,7 +109,7 @@ export default {
formValid: false,
xidUnique: true,
ruleNotNull: (v) => !!v || this.$t('validation.rule.notNull'),
ruleXidUnique: () => this.xidUnique || this.$t('validation.rule.xid.notUnique'),
ruleXidUnique: () => this.xidUnique || this.$t('validation.rule.xid.notUnique')
};
},
Expand All @@ -123,9 +125,14 @@ export default {
},
accept() {
let datapoint = JSON.parse(JSON.stringify(this.datapoint));
datapoint.name = this.datapoint.tempName;
datapoint.xid = this.datapoint.tempXid;
datapoint.description = this.datapoint.tempDescription;
console.debug('datasources.DataPointCreation.vue::accept()');
if (this.formValid) {
this.$emit('accept');
this.$emit('accept', datapoint);
}
},
Expand Down
28 changes: 17 additions & 11 deletions scadalts-ui/src/components/datasources/DataSourceConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<h1>
<span v-if="creator"> Create </span>
<span v-else> Update </span>
<span>
{{ title }}
</span>
<span v-html="title"> </span>
</h1>
</v-col>
<v-col cols="4">
Expand All @@ -23,15 +21,15 @@
<v-col cols="12" :md="8" :sm="12" id="datasource-config--name">
<v-text-field
autofocus
v-model="datasource.name"
v-model="datasource.tempName"
label="DataSource Name"
:rules="[ruleNotNull]"
required
></v-text-field>
</v-col>
<v-col cols="12" :md="4" :sm="12" id="datasource-config--xid">
<v-text-field
v-model="datasource.xid"
v-model="datasource.tempXid"
label="DataSource Export Id"
@input="checkXidUnique"
:rules="[ruleNotNull, ruleXidUnique]"
Expand Down Expand Up @@ -127,8 +125,12 @@ export default {
mounted() {
if (this.creator) {
this.$store.dispatch('getUniqueDataSourceXid').then((resp) => {
this.datasource.xid = resp;
this.datasource.tempXid = resp;
this.datasource = JSON.parse(JSON.stringify(this.datasource));
});
} else {
this.datasource.tempName = this.datasource.name;
this.datasource.tempXid = this.datasource.xid;
}
},
Expand All @@ -138,7 +140,7 @@ export default {
xidUnique: true,
ruleNotNull: (v) => !!v || this.$t('validation.rule.notNull'),
ruleOnlyNumber: (v) => !isNaN(v) || this.$t('validation.rule.onlyNumber'),
ruleXidUnique: () => this.xidUnique || this.$t('validation.rule.xid.notUnique'),
ruleXidUnique: () => this.xidUnique || this.$t('validation.rule.xid.notUnique')
};
},
Expand All @@ -149,8 +151,12 @@ export default {
},
accept() {
console.debug('datasources.DataSourceConfig.vue::accept()');
this.$emit('accept');
let datasource = JSON.parse(JSON.stringify(this.datasource));
datasource.name = this.datasource.tempName;
datasource.xid = this.datasource.tempXid;
console.debug('datasources.DataSourceConfig.vue::accept()');
this.$emit('accept', datasource);
},
onUpdatePeriodTypeUpdate(value) {
Expand All @@ -162,14 +168,14 @@ export default {
this.datasource.id = this.datasource.id || -1;
let resp = await this.$store.dispatch(
'requestGet',
`/datasource/validate?xid=${this.datasource.xid}&id=${this.datasource.id}`,
`/datasource/validate?xid=${this.datasource.tempXid}&id=${this.datasource.id}`,
);
this.xidUnique = resp.unique;
this.$refs.datasourceForm.validate();
} catch (e) {
console.error('Failed to fetch data');
}
},
}
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const dataSourceConfigMixin = {
generateUniqueXid() {
if (this.createMode) {
this.$store.dispatch('getUniqueDataSourceXid').then(resp => {
this.datasource.xid = resp;
this.datasource.tempXid = resp;
this.datasource = JSON.parse(JSON.stringify(this.datasource));
});
}
},
Expand All @@ -69,8 +70,8 @@ export const dataSourceConfigMixin = {
this.$emit('canceled');
},

save() {
this.$emit('saved', this.datasource);
save(data) {
this.$emit('saved', data);
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:creator="createMode"
availablePeriodTypes="1,2,3,8,9,11,26,27"
@cancel="cancel()"
@accept="save()"
@accept="save"
>
<template v-slot:selector>
<slot name="selector"></slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<config
v-if="detailsLoaded"
@canceled="closeEditor()"
@saved="onSaved($event)"
@saved="onSaved"
:datasource="ds"
:createMode="false"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:creator="createMode"
:datapoint="datapoint"
@cancel="cancel()"
@accept="save()"
@accept="save"
>
<template v-slot:selector>
<v-select
Expand Down Expand Up @@ -537,11 +537,11 @@ export default {
this.$emit('canceled');
},
async save() {
async save(data) {
console.debug('VirtualDataSource.point.vue::save()');
await this.validateScript();
if (this.validScript)
this.$emit('saved', this.datapoint);
this.$emit('saved', data);
},
addMsValue(array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:creator="createMode"
availablePeriodTypes="1,2,3,8"
@cancel="cancel()"
@accept="save()"
@accept="save"
>
<template v-slot:selector>
<slot name="selector"></slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<config
v-if="detailsLoaded"
@canceled="closeEditor()"
@saved="onSaved($event)"
@saved="onSaved"
:datasource="ds"
:createMode="false"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:datapoint="datapoint"
:settableDisabled="settingsInputDisabled"
@cancel="cancel()"
@accept="save()"
@accept="save"
>
<template v-slot:selector>
<v-select
Expand Down Expand Up @@ -317,9 +317,9 @@ export default {
this.$emit('canceled');
},
save() {
save(data) {
console.debug('VirtualDataSource.point.vue::save()');
this.$emit('saved', this.datapoint);
this.$emit('saved', data);
},
changeRegisterRange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:datasource="datasource"
:creator="createMode"
@cancel="cancel()"
@accept="save()"
@accept="save"
>
<template v-slot:selector>
<slot name="selector"></slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<config
v-if="detailsLoaded"
@canceled="closeEditor()"
@saved="onSaved($event)"
@saved="onSaved"
:datasource="ds"
:createMode="false"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:creator="createMode"
:datapoint="datapoint"
@cancel="cancel()"
@accept="save()"
@accept="save"
>
<template v-slot:selector>
<v-select
Expand Down Expand Up @@ -142,8 +142,8 @@ export default {
this.$emit('canceled');
},
save() {
this.$emit('saved', this.datapoint);
save(data) {
this.$emit('saved', data);
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:creator="createMode"
availablePeriodTypes="1,2,3,8"
@cancel="cancel()"
@accept="save()"
@accept="save"
>
<template v-slot:selector>
<slot name="selector"></slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<config
v-if="detailsLoaded"
@canceled="closeEditor()"
@saved="onSaved($event)"
@saved="onSaved"
:datasource="ds"
:createMode="false"
/>
Expand Down
Loading

0 comments on commit bda0e41

Please sign in to comment.