Skip to content

Commit e9a679d

Browse files
committed
Add blacklist for addons
1 parent 6ce49de commit e9a679d

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

docs/server/env.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ Codebox use environment variables for defining its conffiguration, here is a lis
77
| WORKSPACE_DIR | Workspace current directory | Shell current directory |
88
| WORKSPACE_NAME | Name for this workspace | "Workspace" |
99
| WORKSPACE_PUBLIC | If defined the workspace will be considered as public | false |
10+
| WORKSPACE_USERS_MAX | Max number of active collaborators on the box | 100 |
1011
| WORKSPACE\_USERS\_MAX | Max number of users | 100 |
1112
| WORKSPACE\_HOOK\_AUTH | Url for the authentification hook | |
1213
| WORKSPACE\_HOOK\_EVENTS | Url for the events hook | |
1314
| WORKSPACE\_HOOK\_SETTINGS | Url for the settings hook | |
1415
| WORKSPACE\_HOOK\_TOKEN | Token to pass as Authorization header for all web hooks | |
1516
| WORKSPACE\_ADDONS\_DIR | Path to the directory where to store installed addons | addons/installed |
17+
| WORKSPACE\_ADDONS\_BLACKLIST | List of addons name blacklisted separated by commas | |
1618
| WORKSPACE\_ADDONS\_DEFAULTS_DIR | Path to the directory where to store (or where are stored) defaults addons | addons/defaults |
1719
| WORKSPACE\_ADDONS\_TEMP_DIR | Path to the directory where to temporary store installed addons | system temporary directory |

src/core/cb.addons/addon.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ var exec = function(command, options) {
3232
return deferred.promise;
3333
}
3434

35-
var Addon = function(logger, _rootPath) {
35+
var Addon = function(logger, _rootPath, options) {
3636
this.root = _rootPath;
3737
this.infos = {};
38+
this.options = options;
3839

3940
// Load addon infos from an addon's directory
4041
this.load = Q.fbind(function(addonDir) {
@@ -86,6 +87,11 @@ var Addon = function(logger, _rootPath) {
8687
return _.size(this.infos.dependencies || {}) > 0;
8788
};
8889

90+
// Check if the addon is blacklisted
91+
this.isBlacklisted = function() {
92+
return _.contains(this.options.blacklist, this.infos.name);
93+
};
94+
8995
// Optimize the addon
9096
this.optimizeClient = function(force) {
9197
var that = this;

src/core/cb.addons/main.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ function setup(options, imports, register, app) {
3737
};
3838

3939
// Load addons list from a directory return as a map name -> addon
40-
var loadAddonsInfos = function(addonsRoot, options) {
40+
var loadAddonsInfos = function(addonsRoot, _options) {
4141
// Diretcory to explore
4242
addonsRoot = addonsRoot || configAddonsPath;
4343

4444
// Options
45-
options = _.defaults({}, options || {}, {
45+
_options = _.defaults({}, _options || {}, {
4646
ignoreError: false
4747
});
4848

@@ -52,14 +52,14 @@ function setup(options, imports, register, app) {
5252
if (dir.indexOf('.') == 0) return Q(addons);
5353

5454
var addonPath = path.join(addonsRoot, dir);
55-
var addon = new Addon(logger, addonPath);
55+
var addon = new Addon(logger, addonPath, options);
5656
return addon.load().then(function() {
5757
addon.infos.default = isDefaultAddon(addon);
5858
addons[addon.infos.name] = addon;
5959
return Q(addons);
6060
}, function(err) {
6161
logger.error("error", err);
62-
if (options.ignoreError) {
62+
if (_options.ignoreError) {
6363
// When ignoring error
6464
// it will check that the addon is not a symlink
6565
// and unlink invalid ones
@@ -123,6 +123,12 @@ function setup(options, imports, register, app) {
123123
}
124124
})
125125
.then(function() {
126+
// Blacklist
127+
if (addon.isBlacklisted()) {
128+
logger.error("Default addon", addon.infos.name, "is blacklisted");
129+
return Q();
130+
}
131+
126132
// Relink it
127133
//logger.log("link ", addon.root, configAddonsPath)
128134
return addon.symlink(configAddonsPath);
@@ -131,10 +137,10 @@ function setup(options, imports, register, app) {
131137
};
132138

133139
// Install an addon by its git url
134-
var installAddon = function(git, options) {
140+
var installAddon = function(git, _options) {
135141
var addon, tempDir;
136142

137-
options = _.defaults({}, options || {}, {
143+
_options = _.defaults({}, _options || {}, {
138144

139145
});
140146

@@ -158,9 +164,14 @@ function setup(options, imports, register, app) {
158164
return repo.checkout(gitRef);
159165
}).then(function() {
160166
// Load addon
161-
addon = new Addon(logger, tempDir);
167+
addon = new Addon(logger, tempDir, options);
162168
return addon.load();
163169
}).then(function() {
170+
// Blacklist
171+
if (addon.isBlacklisted()) {
172+
return Q.reject(new Error("Addon "+addon.infos.name+"is blacklisted"));
173+
}
174+
164175
// Valid installation of addon with a hook
165176
return hooks.use("addons", addon.infos);
166177
}).then(function() {

src/core/codebox.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ var start = function(config) {
4242
// Base path
4343
'path': process.env.WORKSPACE_ADDONS_DIR || path.resolve(__dirname + '/../../.addons'),
4444
'defaultsPath': process.env.WORKSPACE_ADDONS_DEFAULTS_DIR || path.resolve(__dirname + '/../addons'),
45-
'tempPath': process.env.WORKSPACE_ADDONS_TEMP_DIR || os.tmpDir()
45+
'tempPath': process.env.WORKSPACE_ADDONS_TEMP_DIR || os.tmpDir(),
46+
'blacklist': (process.env.WORKSPACE_ADDONS_BLACKLIST || "").split(",")
4647
},
4748
'users': {
4849
// Max number of collaborators
@@ -119,7 +120,8 @@ var start = function(config) {
119120
'dev': config.dev,
120121
'path': config.addons.path,
121122
'tempPath': config.addons.tempPath,
122-
'defaultsPath': config.addons.defaultsPath
123+
'defaultsPath': config.addons.defaultsPath,
124+
'blacklist': config.addons.blacklist
123125
},
124126

125127
// Express server

0 commit comments

Comments
 (0)