Skip to content

Commit 6e84bb5

Browse files
committed
[lua] Ask for permission to open a WebSocket from scripts
1 parent b9241e6 commit 6e84bb5

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

data/strings/en.ini

+2
Original file line numberDiff line numberDiff line change
@@ -1377,11 +1377,13 @@ title = Security
13771377
script_label = The following script:
13781378
file_label = wants to access to this file:
13791379
command_label = wants to execute the following command:
1380+
websocket_label = wants to open a WebSocket connection to this URL:
13801381
dont_show_for_this_access = Don't show this specific alert again for this script
13811382
dont_show_for_this_script = Give full trust to this script
13821383
allow_execute_access = &Allow Execute Access
13831384
allow_write_access = &Allow Write Access
13841385
allow_read_access = &Allow Read Access
1386+
allow_open_conn_access = &Allow to Open Connections
13851387
give_full_access = Give Script Full &Access
13861388
stop_script = &Stop Script
13871389

src/app/script/security.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ bool ask_access(lua_State* L,
136136
return true;
137137

138138
std::string allowButtonText =
139+
mode == FileAccessMode::OpenSocket ?
140+
Strings::script_access_allow_open_conn_access():
139141
mode == FileAccessMode::Execute ?
140142
Strings::script_access_allow_execute_access():
141143
mode == FileAccessMode::Write ?
@@ -150,6 +152,7 @@ bool ask_access(lua_State* L,
150152
switch (resourceType) {
151153
case ResourceType::File: label = Strings::script_access_file_label(); break;
152154
case ResourceType::Command: label = Strings::script_access_command_label(); break;
155+
case ResourceType::WebSocket: label = Strings::script_access_websocket_label(); break;
153156
}
154157
dlg.fileLabel()->setText(label);
155158
}

src/app/script/security.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ namespace script {
2323
Write = 2,
2424
Read = 4,
2525
Full = 7,
26+
OpenSocket = 8,
2627
};
2728

2829
enum class ResourceType {
2930
File,
3031
Command,
32+
WebSocket,
3133
};
3234

3335
int secure_io_open(lua_State* L);

src/app/script/websocket_class.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Aseprite
2-
// Copyright (C) 2018-2020 Igara Studio S.A.
3-
// Copyright (C) 2018 David Capello
2+
// Copyright (C) 2021 Igara Studio S.A.
43
//
54
// This program is distributed under the terms of
65
// the End-User License Agreement for Aseprite.
@@ -13,6 +12,7 @@
1312
#include "app/console.h"
1413
#include "app/script/engine.h"
1514
#include "app/script/luacpp.h"
15+
#include "app/script/security.h"
1616
#include "ui/system.h"
1717

1818
#include <ixwebsocket/IXNetSystem.h>
@@ -39,6 +39,9 @@ int WebSocket_new(lua_State* L)
3939
if (lua_istable(L, 1)) {
4040
lua_getfield(L, 1, "url");
4141
if (const char* s = lua_tostring(L, -1)) {
42+
if (!ask_access(L, s, FileAccessMode::OpenSocket, ResourceType::WebSocket))
43+
return luaL_error(L, "the script doesn't have access to create a WebSocket for '%s'", s);
44+
4245
ws->setUrl(s);
4346
}
4447
lua_pop(L, 1);
@@ -180,7 +183,7 @@ const Property WebSocket_properties[] = {
180183
{ nullptr, nullptr, nullptr }
181184
};
182185

183-
} // namespace { }
186+
} // anonymous namespace
184187

185188
using WebSocket = ix::WebSocket;
186189
DEF_MTNAME(WebSocket);

0 commit comments

Comments
 (0)