Skip to content

Commit 59c5f7f

Browse files
committed
security: remove project script property, build for production
1 parent 4902b6a commit 59c5f7f

File tree

9 files changed

+35
-6
lines changed

9 files changed

+35
-6
lines changed

client/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@
8686
</div>
8787
</div>
8888
</app-root>
89-
<script src="runtime.9136a61a9b98f987.js" type="module"></script><script src="polyfills.d7de05f9af2fb559.js" type="module"></script><script src="scripts.d9e6ee984bf6f3b7.js" defer></script><script src="main.f8215ed2324002a9.js" type="module"></script></body>
89+
<script src="runtime.9136a61a9b98f987.js" type="module"></script><script src="polyfills.d7de05f9af2fb559.js" type="module"></script><script src="scripts.d9e6ee984bf6f3b7.js" defer></script><script src="main.cbcce26a6b6aacee.js" type="module"></script></body>
9090

9191
</html>
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fuxa",
3-
"version": "1.3.0-2778",
3+
"version": "1.3.0-2779",
44
"keywords": [],
55
"author": "frangoteam <info@frangoteam.org>",
66
"description": "Web-based Process Visualization (SCADA/HMI/Dashboard) software",

client/src/app/_services/script.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ export class ScriptService {
241241

242242
public async $runServerScript(scriptName: string, ...params: any[]) {
243243
let scriptToRun = Utils.clone(this.projectService.getScripts().find(dataScript => dataScript.name == scriptName));
244+
if (!scriptToRun) {
245+
return null;
246+
}
244247
scriptToRun.parameters = params;
245248
return await lastValueFrom(this.runScript(scriptToRun, false));
246249
}

client/src/app/fuxa-view/fuxa-view.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,9 @@ export class FuxaViewComponent implements OnInit, AfterViewInit, OnDestroy {
10041004
onRunScript(event: GaugeEvent) {
10051005
if (event.actparam) {
10061006
let torun = Utils.clone(this.projectService.getScripts().find(dataScript => dataScript.id == event.actparam));
1007+
if (!torun) {
1008+
return;
1009+
}
10071010
torun.parameters = Utils.clone(<ScriptParam[]>event.actoptions[SCRIPT_PARAMS_MAP]);
10081011
const placeholders = torun.parameters.filter(param => param.value?.startsWith(PlaceholderDevice.id)).map(param => param.value);
10091012
if (placeholders?.length) {

client/src/app/gauges/controls/html-table/data-table/data-table.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ export class DataTableComponent implements OnInit, AfterViewInit, OnDestroy {
396396
private runScript(event: GaugeEvent, selected: MatRow) {
397397
if (event.actparam) {
398398
let torun = Utils.clone(this.projectService.getScripts().find(dataScript => dataScript.id == event.actparam));
399+
if (!torun) {
400+
return;
401+
}
399402
torun.parameters = <ScriptParam[]>Utils.clone(event.actoptions[SCRIPT_PARAMS_MAP]);
400403
torun.parameters.forEach(param => {
401404
if (Utils.isNullOrUndefined(param.value)) {

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fuxa-server",
3-
"version": "1.3.0-2778",
3+
"version": "1.3.0-2779",
44
"description": "Web-based Process Visualization (SCADA/HMI/Dashboard) software",
55
"main": "main.js",
66
"scripts": {

server/runtime/project/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,22 @@ function _filterProjectPermission(userPermission) {
928928
// from device remove the not used (no permission)
929929
// delete result.devices;
930930
delete result.server;
931+
if (Array.isArray(result.scripts)) {
932+
// Keep only scripts authorised for the current user. For authorised
933+
// server-side scripts, retain just the metadata needed for event
934+
// bindings and execution requests; do not expose source code.
935+
result.scripts = result.scripts.filter(script => {
936+
return script && runtime.scriptsMgr.isAuthorised(script, userPermission);
937+
}).map(script => {
938+
delete script.permission;
939+
delete script.permissionRoles;
940+
if (script.mode === 'CLIENT') {
941+
return script;
942+
}
943+
delete script.code;
944+
return script;
945+
});
946+
}
931947
// check navigation permission
932948
if (result.hmi.layout && result.hmi.layout.navigation.items) {
933949
for (var i = result.hmi.layout.navigation.items.length - 1; i >= 0; i--) {

server/runtime/scripts/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ function ScriptsManager(_runtime) {
8888
const st = scriptModule.getScript(_script);
8989
var admin = (permission === -1 || permission === 255) ? true : false;
9090
if (runtime.settings.userRole) {
91+
admin = admin || permission?.groups === -1 || permission?.groups === 255;
92+
if (admin) {
93+
return true;
94+
}
9195
if (!st.permissionRoles || !st.permissionRoles.enabled) {
9296
return true;
9397
}

0 commit comments

Comments
 (0)