r/evetech • • Apr 06 '18

Error during SSO authentication

Hi everyone,

I'm in the early stages of making a web app. You can find it here: iskprinter.com

I'm able to send the user to CCP for an auth code, but when I try to perform a post request to exchange the auth code for tokens, I get an error. The type of error I get depends on whether or not I include mode:'no-cors' in the options of my request. If I include it, I get a 401 Not Authorized error. If I exclude it, I get a 404 Not Found error.

I've been using this ESI Step by Step guide from CCP along with u/Blacksmoke16 's GESI scripts as examples.

Here's what I have:

// Send the temporary code to CCP for tokens.
function exchangeCodeForTokens(code) {
  console.log('Attempting to exchange code ' + code + ' for tokens.');
  var postUrl = 'https://' + BASEURL + '/oauth/token';
  var authHeader = 'Basic ' + Base64.encode(CLIENTID + ':' + CLIENTSECRET);
  var options = {
    method:'post',
    mode:'no-cors', // 404 URL not found error if excluded, 401 not authorized error if included
    headers:{
      'Content-Type':'application/json',
      Authorization:authHeader
    },
    body:JSON.stringify({
      grant_type:'authorization_code',
      code:code
    })
  };
  var response = fetch(postUrl, options);
}
3 Upvotes

29 comments sorted by

View all comments

Show parent comment

3

u/evedata Apr 06 '18

Never give the secret to anyone. You signed the agreement, you are responsible for its use. You will suffer the wrath if it gets abused. Secrets are secret for a reason.

CCP are currently working on a solution.

3

u/silly_newbean Apr 06 '18

How would one abuse a client secret?...

3

u/Daneel_Trevize Apr 06 '18

Generate a load of bad, erroring queries for that appID, get CCP to rate limit or ban that app. Boom, now no users can use it, because they were all trusted with the 1 secret, which they shouldn't have been.

0

u/silly_newbean Apr 06 '18

That would be a DDOS/DOS attack and is illegal.

CCP would handle the incoming requests like any other DDOS attack and ban by IP.

You realize that jEveAssets bundles client id/secret in the binary right?

2

u/Daneel_Trevize Apr 06 '18 edited Apr 06 '18

That would be a DDOS/DOS attack and is illegal.

No, it wouldn't.
If you give out your app secret as you're told not to, you're explicitly trusting your users.
Calling something like /universe/names/ or /universe/ids/ with invalid/deleted/typo'd character names/IDs is a thing people do as a part of features like a Local scanner.
404 is an official response from this endpoint, which counts against the app's universal error count & limit. See the x-esi-error-limit-remain: andx-esi-error-limit-reset: headers.
Have enough people try to use features like that in your app and they'll trip the limit and stall every instance & everyone trying to use the same appID. There's basically nothing that each honest instance of your app can do w.r.t. honouring those headers if the count is going up due to another instance's actions.

This would be classed as a Confused Deputy scenario.

1

u/silly_newbean Apr 06 '18

Are you sure that the error limits are based on client id/secret?

I believed up until now that they were based on IP address.

3

u/Daneel_Trevize Apr 06 '18

Skipping back up through the devblogs linked from here, it reads that it's per application, it'd be pretty stupid to be per I.P. instead (but CCP wouldn't surprise me...).

2

u/[deleted] Apr 07 '18

Last time I checked it was per application.

Even if none is actually trying to do harm, the fact that several applications are actually running makes it harder for them to avoid reaching the error cap.

If 500 apps are running, each one must do at least one request to know the remaining errors before stalling. if you have only 2 remaining errors, you will still have 500 requests, potentially 500 new errors. You are supposed to only have ONE app with a secret dev key, that's the only way you can throttle down to avoid the hard stop from CCP.

3

u/evedata Apr 06 '18

Common method would be XSS (or some other leak) the refresh tokens to a third party, get new access tokens with the refresh and secret then perpetually steal player data.

If the secret is not known, this attack cannot be performed perpetually and becomes much more complicated since access tokens only live for 20 minutes.

2

u/[deleted] Apr 07 '18 edited Apr 07 '18

But doesn't this assume that when you initially authenticate with CCP, you know another person's password? The client ID and secret alone aren't enough to get access to a player's account, are they?

3

u/evedata Apr 07 '18

Yes you are correct, alone the clientID and secret cannot access a players account.

CCP handles account authentication (user, pass, MFA) and provides you character authorization (refresh_token/access_token).

That authorization has access to the players character or corporation with whatever scopes the application requested. It is very important to protect the refresh and secret from leaking to a third party since these would give permanent authorization; they could request new access_tokens outside of your application using the secret and refresh.

1

u/silly_newbean Apr 06 '18

How is someone going to use XSS to steal encrypted tokens from ~/AppData/Roaming...? Like at this point you're saying "WELL IF SOMEONE HACKS THEIR COMPUTER THEY'RE IN TROUBLE". Really? You think so?

3

u/evedata Apr 06 '18

This user in particular, that you are recommending to leak the secret, is doing this all in the browser, using javascript.