Skip to content

Commit 2aa14ad

Browse files
gyratorycircusflovilmart
authored andcommitted
Only allow basic auth credentials with a known appId (#2574)
* Only allow basic auth credentials with a known appId * Update middlewares.js * Updating basic auth tests to use valid appId
1 parent 8eafe45 commit 2aa14ad

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

spec/index.spec.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,31 @@ describe('server', () => {
2626
});
2727

2828
it('support http basic authentication with masterkey', done => {
29-
request.get({
30-
url: 'http://localhost:8378/1/classes/TestObject',
31-
headers: {
32-
'Authorization': 'Basic ' + new Buffer('test:' + 'test').toString('base64')
33-
}
34-
}, (error, response, body) => {
35-
expect(response.statusCode).toEqual(200);
36-
done();
37-
});
29+
reconfigureServer({ appId: 'test' }).then(() => {
30+
request.get({
31+
url: 'http://localhost:8378/1/classes/TestObject',
32+
headers: {
33+
'Authorization': 'Basic ' + new Buffer('test:' + 'test').toString('base64')
34+
}
35+
}, (error, response, body) => {
36+
expect(response.statusCode).toEqual(200);
37+
done();
38+
});
39+
})
3840
});
3941

4042
it('support http basic authentication with javascriptKey', done => {
41-
request.get({
42-
url: 'http://localhost:8378/1/classes/TestObject',
43-
headers: {
44-
'Authorization': 'Basic ' + new Buffer('test:javascript-key=' + 'test').toString('base64')
45-
}
46-
}, (error, response, body) => {
47-
expect(response.statusCode).toEqual(200);
48-
done();
49-
});
43+
reconfigureServer({ appId: 'test' }).then(() => {
44+
request.get({
45+
url: 'http://localhost:8378/1/classes/TestObject',
46+
headers: {
47+
'Authorization': 'Basic ' + new Buffer('test:javascript-key=' + 'test').toString('base64')
48+
}
49+
}, (error, response, body) => {
50+
expect(response.statusCode).toEqual(200);
51+
done();
52+
});
53+
})
5054
});
5155

5256
it('fails if database is unreachable', done => {

src/middlewares.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ export function handleParseHeaders(req, res, next) {
3131
var basicAuth = httpAuth(req);
3232

3333
if (basicAuth) {
34-
info.appId = basicAuth.appId
35-
info.masterKey = basicAuth.masterKey || info.masterKey;
36-
info.javascriptKey = basicAuth.javascriptKey || info.javascriptKey;
34+
var basicAuthAppId = basicAuth.appId;
35+
if (AppCache.get(basicAuthAppId)) {
36+
info.appId = basicAuthAppId;
37+
info.masterKey = basicAuth.masterKey || info.masterKey;
38+
info.javascriptKey = basicAuth.javascriptKey || info.javascriptKey;
39+
}
3740
}
3841

3942
if (req.body) {

0 commit comments

Comments
 (0)