Skip to content

Commit

Permalink
Sanitize vis instance
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Jul 16, 2024
1 parent d89c9cd commit 41e5414
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/iobroker.vis-2/src/src/Toolbar/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ const Settings: React.FC<SettingsProps> = props => {
const [projectMode, setProjectMode] = useState(0);

const [settings, setSettings] = useState<ProjectSettings>({} as ProjectSettings);
const [instance, setInstance] = useState(window.localStorage.getItem('visInstance'));
const [instance, setInstance] = useState('');
/* eslint no-underscore-dangle: 0 */
useEffect(() => {
const _settings = { ...store.getState().visProject.___settings };
if (_settings.reloadOnEdit === undefined) {
_settings.reloadOnEdit = true;
}

let _instance = (window.localStorage.getItem('visInstance') || '').replace(/^"/, '').replace(/"$/, '');
setInstance(_instance);

// read project settings
props.socket.readDir(`${props.adapterName}.${props.instance}`, props.projectName)
.then(files => {
Expand Down
15 changes: 13 additions & 2 deletions packages/iobroker.vis-2/src/src/Vis/visEngine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class VisEngine extends React.Component<VisEngineProps, VisEngineState> {
projectPrefix: this.props.projectName,
_: translate,
dateFormat: '',
instance: window.localStorage.getItem('visInstance'),
instance: (window.localStorage.getItem('visInstance') || '').replace(/^"/, '').replace(/"$/, ''),
loginRequired: false,
viewsActiveFilter: this.viewsActiveFilter,
onChangeCallbacks: this.onChangeCallbacks,
Expand Down Expand Up @@ -1776,7 +1776,18 @@ class VisEngine extends React.Component<VisEngineProps, VisEngineState> {
};

onUserCommand(instance: string, command: string, data: any) {
const currentInstance = window.localStorage.getItem('visInstance');
const currentInstance = (window.localStorage.getItem('visInstance') || '').replace(/^"/, '').replace(/"$/, '');

if (instance === null || instance === undefined) {
instance = '';
} else {
instance = instance.toString();
}

if (instance && typeof instance === 'string') {
instance = instance.replace(/^"/, '').replace(/"$/, '');
}

if (!instance || (instance !== currentInstance && instance !== 'FFFFFFFF' && !instance.includes('*'))) {
return false;
}
Expand Down

0 comments on commit 41e5414

Please sign in to comment.