Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No IP address in request when directAccess: true #8806

Open
4 tasks done
mtrezza opened this issue Nov 16, 2023 · 1 comment
Open
4 tasks done

No IP address in request when directAccess: true #8806

mtrezza opened this issue Nov 16, 2023 · 1 comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@mtrezza
Copy link
Member

mtrezza commented Nov 16, 2023

New Issue Checklist

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.

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());
});
});

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());
});

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:

Parse.CoreManager.setRESTController(RESTController);

See #8808 for context about this override.

Steps to reproduce

  1. Set Parse Server option directAccess: true.
  2. Save a Parse.User.
  3. The request object in Parse.Cloud.beforeSave('_User', async request => { ... }); has the property request.ip set to undefined.

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
Copy link

parse-github-assistant bot commented Nov 16, 2023

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

1 participant