-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
When setting the Parse Server option directAccess: true
, the request object in triggers have no IP address set.
This could be considered a characteristic of the direct access feature, but there are a few test cases that expect the IP address to be set, so it should probably be considered a bug.
parse-server/spec/CloudCode.spec.js
Lines 2006 to 2015 in 4b3ce20
describe('cloud functions', () => { | |
it('Should have request ip', done => { | |
Parse.Cloud.define('myFunction', req => { | |
expect(req.ip).toBeDefined(); | |
return 'success'; | |
}); | |
Parse.Cloud.run('myFunction', {}).then(() => done()); | |
}); | |
}); |
parse-server/spec/CloudCode.spec.js
Lines 2083 to 2091 in 4b3ce20
it('should have request ip', done => { | |
Parse.Cloud.afterSave('MyObject', req => { | |
expect(req.ip).toBeDefined(); | |
}); | |
const MyObject = Parse.Object.extend('MyObject'); | |
const myObject = new MyObject(); | |
myObject.save().then(() => done()); | |
}); |
parse-server/spec/CloudCode.spec.js
Lines 2468 to 2483 in 4b3ce20
it('should have request ip', done => { | |
Parse.Cloud.beforeFind('MyObject', req => { | |
expect(req.ip).toBeDefined(); | |
}); | |
const MyObject = Parse.Object.extend('MyObject'); | |
const myObject = new MyObject(); | |
myObject | |
.save() | |
.then(myObj => { | |
const query = new Parse.Query('MyObject'); | |
query.equalTo('objectId', myObj.id); | |
return Promise.all([query.get(myObj.id), query.first(), query.find()]); | |
}) | |
.then(() => done()); | |
}); |
All these tests pass, only because the test suite does not actually use the ParseServerRESTController because the test helper always sets the normal REST controller:
Line 169 in 4b3ce20
Parse.CoreManager.setRESTController(RESTController); |
See #8808 for context about this override.
Steps to reproduce
- Set Parse Server option
directAccess: true
. - Save a Parse.User.
- The
request
object inParse.Cloud.beforeSave('_User', async request => { ... });
has the propertyrequest.ip
set toundefined
.
Actual Outcome
request.ip
set to undefined
Expected Outcome
request.ip
set to localhost, e.g. 127.0.0.1
in IPv4 environments or ::1
in IPv6 environments.
Possibly just set the IP with a simple:
function getLoopbackAddress() {
const isIPv6Supported = os.networkInterfaces().lo0?.some(iface => iface.family === 'IPv6');
return isIPv6Supported ? '::1' : '127.0.0.1';
}
Environment
Server
- Parse Server version:
6.3.1