Regarding loginAs in Version 5.0.0

Hi,

I found below info, if so, the MASTER_KEY seems will be exposed to the client side, which is quite unsafe. How about adding the beforeLoginAs hook at least? So we could handle them at the cloud side …
Thanks a lot.

connection.request('GET', '/parse/loginAs?%s' % params, '', {
       "X-Parse-Application-Id": "${APPLICATION_ID}",
       "X-Parse-REST-API-Key": "${REST_API_KEY}",
       "X-Parse-Master-Key": "${MASTER_KEY}",
       "X-Parse-Revocable-Session": "1"
     })
...
 the /loginAs endpoint does not run the beforeLogin or afterLogin hooks

Well the point here is that loginAs allows you to login as a user without a password - hence why you need a masterKey because otherwise any user could send a loginAs request, which would expose every single user. If you want to use a loginAs request on the client side I would require the input of the masterKey so that it’s not stored in code.

1 Like

I think @xeoshow has a point. Exposing the master key on the client side seems quite a big risk for a “regular feature”. Maybe there should be an alternative server-side validation for allowing / rejecting the endpoint. Like a beforeLoginAs trigger? That way one could make use of roles and for example only allowing users of an admin role to use the endpoint.

Thank you for kind help @dblythy @Manuel , In our scenario, the higher level roles could act as the other roles, so we would like to pass the username/sessionToken/loginAsUserName (from client side) in the beforeLoginAs (get the role of the username, validate the sessionToken, check the auth level, etc) to dertermine if it could invoke the loginAs API.

Currently we could write a cloud function to do that, and in the cloud function, invoke the rest api loginAs. While this solution seems not that straightforward…

Again, thanks so much for kind help!

@xeoshow Please feel free to open an issue in Parse Server and suggest a beforeLoginAs trigger if you think it makes sense and helps in your use case.

My understanding was loginAs is intended to allow the request to happen in cloud code (where you’d do all the validation in the trigger), and then pass the return session token as response. But I guess it would add an extra layer of complexity and we may as well have a custom trigger where you can allow certain users to make the loginAs call.

1 Like

Parse Dashboard is using the loginAs endpoint with the master key I suppose. But that is not really applicable if a regular client app wants to use that endpoint. But I’m not sure how we’d secure the endpoint, given that the non-existence of a beforeLoginAs trigger means no restriction. So maybe it’s best to keep it in Cloud Code only?

1 Like

Not sure why the submit button is disabled… Keeping it in Cloud Code only seems is a good solution.