Skip to content

Commit 8d5bb4b

Browse files
authored
Merge pull request livecode#6569 from montegoulding/bugfix-21343
[[ Bug 21343 ]] Add extension security permission
2 parents 60bcb94 + ea1ccb9 commit 8d5bb4b

10 files changed

Lines changed: 89 additions & 6 deletions

File tree

docs/dictionary/property/secureMode.lcdoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ The application cannot access remote files with the URL <keyword>. The
4141
If the application is started from a Unix or Windows command line, this
4242
property can be set to true on startup by using the -f option.
4343

44+
The application also can not use the <load extension> command to load an extension
45+
from a file or data.
46+
4447
>*Important:* Once the <secureMode> <property> is set to true, it
4548
> cannot be set back to false. To change it back to true, you must quit
4649
> and restart the <application>.
4750

51+
Changes:
52+
In version 9.5 the loading of extensions was added to the secureMode
53+
restrictions.
54+
4855
References: write to file (command), open file (command), put (command),
4956
launch (command), open process (command), read from file (command),
5057
get (command), function (control structure), shell (function),
@@ -53,7 +60,7 @@ queryRegistry (function), property (glossary), stack file (glossary),
5360
Windows (glossary), web server (glossary), keyword (glossary),
5461
registry (glossary), function (glossary), command (glossary),
5562
application (glossary), file (keyword), securityPermissions (property),
56-
securityCategories (property)
63+
securityCategories (property), load extension (command)
5764

5865
Tags: file system
5966

docs/dictionary/property/securityCategories.lcdoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ supported security categories. Returned values are:
3131
* doalternate - use of the 'do ... as ...' alternate language
3232
execution feature
3333
* external - loading externals
34+
* extension - loading extensions from file or data. Extensions included when
35+
building a standalone are not restricted.
3436

37+
Changes:
38+
In version 9.5 the extension category was added to restrict loading of
39+
extensions.
3540

3641
References: launch (command), property (glossary),
37-
securityPermissions (property), secureMode (property)
42+
securityPermissions (property), secureMode (property), load extension (command)
3843

3944
Tags: file system
4045

docs/dictionary/property/securityPermissions.lcdoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,19 @@ delimited values for <permissionList> are:
4141
* doalternate - use of the 'do ... as ...' alternate language
4242
execution feature
4343
* external - loading externals
44-
44+
* extension - loading extensions from file or data. Extensions included when
45+
building a standalone are not restricted.
4546

4647
Once <securityPermissions> is set, the security permissions can only be
4748
reduced and not increased.
4849

50+
Changes:
51+
In version 9.5 the extension category was added to restrict loading of
52+
extensions.
53+
4954
References: launch (command), empty (constant), files (function),
5055
property (glossary), application (glossary), web server (glossary),
51-
securityCategories (property), secureMode (property)
56+
securityCategories (property), secureMode (property), load extension (command)
5257

5358
Tags: file system
5459

docs/notes/bugfix-21343.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Add `extension` as a category to the `securityPermissions` property to restrict the `load extension` command

engine/src/exec-engine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static MCExecSetTypeElementInfo _kMCEngineSecurityCategoriesElementInfo[] =
102102
{ "applescript", kMCSecureModeTypeApplescriptBit },
103103
{ "doalternate", kMCSecureModeTypeDoalternateBit },
104104
{ "external", kMCSecureModeTypeExternalBit },
105+
{ "extension", kMCSecureModeTypeExtensionBit },
105106
};
106107

107108
static MCExecSetTypeInfo _kMCEngineSecurityCategoriesTypeInfo =

engine/src/exec-extension.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ void MCEngineAddExtensionsFromModulesArray(MCAutoScriptModuleRefArray& p_modules
225225

226226
void MCEngineLoadExtensionFromData(MCExecContext& ctxt, MCDataRef p_extension_data, MCStringRef p_resource_path)
227227
{
228+
if (!MCSecureModeCanAccessExtension())
229+
{
230+
ctxt . SetTheResultToStaticCString("no permission to load module");
231+
return;
232+
}
233+
228234
MCAutoScriptModuleRefArray t_modules;
229235
if (!MCScriptCreateModulesFromData(p_extension_data, t_modules))
230236
{

engine/src/securemode.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ bool MCSecureModeCanAccessExternal(void)
133133
return ((MCsecuremode & MC_SECUREMODE_EXTERNAL) == 0);
134134
}
135135

136+
bool MCSecureModeCanAccessExtension(void)
137+
{
138+
return ((MCsecuremode & MC_SECUREMODE_EXTENSION) == 0);
139+
}
140+
136141
bool MCSecureModeCheckPrivacy(uint2 line, uint2 pos)
137142
{
138143
if ((MCsecuremode & MC_SECUREMODE_PRIVACY) == 0)

engine/src/securemode.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum MCSecureModeType
3030
kMCSecureModeTypeApplescriptBit,
3131
kMCSecureModeTypeDoalternateBit,
3232
kMCSecureModeTypeExternalBit,
33+
kMCSecureModeTypeExtensionBit,
3334
};
3435

3536
#define MC_SECUREMODE_DISK (1 << kMCSecureModeTypeDiskBit)
@@ -42,13 +43,14 @@ enum MCSecureModeType
4243
#define MC_SECUREMODE_APPLESCRIPT (1 << kMCSecureModeTypeApplescriptBit)
4344
#define MC_SECUREMODE_DOALTERNATE (1 << kMCSecureModeTypeDoalternateBit)
4445
#define MC_SECUREMODE_EXTERNAL (1 << kMCSecureModeTypeExternalBit)
46+
#define MC_SECUREMODE_EXTENSION (1 << kMCSecureModeTypeExtensionBit)
4547

4648
#define MC_SECUREMODE_ALL (MC_SECUREMODE_DISK | MC_SECUREMODE_NETWORK | MC_SECUREMODE_PROCESS \
4749
| MC_SECUREMODE_REGISTRY_READ | MC_SECUREMODE_REGISTRY_WRITE \
4850
| MC_SECUREMODE_PRINT | MC_SECUREMODE_PRIVACY | MC_SECUREMODE_APPLESCRIPT \
49-
| MC_SECUREMODE_DOALTERNATE | MC_SECUREMODE_EXTERNAL)
51+
| MC_SECUREMODE_DOALTERNATE | MC_SECUREMODE_EXTERNAL | MC_SECUREMODE_EXTENSION)
5052

51-
#define MC_SECUREMODE_MODECOUNT (10)
53+
#define MC_SECUREMODE_MODECOUNT (11)
5254

5355
extern const char *MCsecuremode_strings[MC_SECUREMODE_MODECOUNT];
5456

@@ -71,12 +73,14 @@ bool MCSecureModeCheckPrivacy(uint2 line = 0, uint2 pos = 0);
7173
bool MCSecureModeCheckAppleScript(uint2 line = 0, uint2 pos = 0);
7274
bool MCSecureModeCheckDoAlternate(uint2 line = 0, uint2 pos = 0);
7375
bool MCSecureModeCheckExternal(uint2 line = 0, uint2 pos = 0);
76+
bool MCSecureModeCheckExtension(uint2 line = 0, uint2 pos = 0);
7477

7578
bool MCSecureModeCanAccessDisk(void);
7679
bool MCSecureModeCanAccessNetwork(void);
7780
bool MCSecureModeCanAccessPrinter(void);
7881
bool MCSecureModeCanAccessDoAlternate(void);
7982
bool MCSecureModeCanAccessExternal(void);
83+
bool MCSecureModeCanAccessExtension(void);
8084

8185
// MW-2013-08-07: [[ Bug 10865 ]] New check method for whether AppleScript is
8286
// enabled.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
library com.livecode.lcs_tests.core.security.extension
2+
3+
use com.livecode.engine
4+
5+
public handler TestCoreSecurityExtension() returns String
6+
return "Foo"
7+
end handler
8+
9+
end library
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
script "CoreSecurityPermissions"
2+
/*
3+
Copyright (C) 2018 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
on TestSetup
20+
TestSkipIfNot "securityPermissions", "set"
21+
end TestSetup
22+
23+
on TestSecurityPermissionExtension
24+
local tCategories
25+
put the securityCategories into tCategories
26+
TestAssert "default securityCategories contains extension", "extension" is among the items of tCategories
27+
28+
filter items of tCategories without "extension"
29+
set the securityPermissions to tCategories
30+
TestAssert "extension can be removed from securityPermissions", the securityPermissions is tCategories
31+
32+
local tError
33+
try
34+
TestLoadAuxiliaryExtension "_extension"
35+
catch tError
36+
-- TestLoadAuxiliaryExtension throws the result on failure
37+
end try
38+
TestAssert "load extension fails with no permission", tError is not empty
39+
40+
end TestSecurityPermissionExtension

0 commit comments

Comments
 (0)