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

OAUTH very seriously error with fake base64 decode #4835

Closed
psy21d opened this issue Jul 29, 2015 · 12 comments
Closed

OAUTH very seriously error with fake base64 decode #4835

psy21d opened this issue Jul 29, 2015 · 12 comments

Comments

@psy21d
Copy link

psy21d commented Jul 29, 2015

meteor/packages/oauth/oauth_server.js

Google it:
(oauth_server.js:78) Unable to parse state from OAuth query: FAKEFAKEKAKE

People get drubbing together with obtaining query.state on many oauth services, because oauth_server.js parse answer as base 64 without disassembling when it is not base 64 at all.

And, no information on internet about this problem.
oauthyarr

Please, fix it recently.

oauth

@psy21d
Copy link
Author

psy21d commented Jul 29, 2015

There is:

string: "�Õ�I¨¯­ª¯spä"
query: {
    close: "close"
    code: "711d643a3b6cb7b523"
    state: "HNWASaivraqvc3Dk4"
}

Need:

string: "HNWASaivraqvc3Dk4"

@psy21d
Copy link
Author

psy21d commented Jul 29, 2015

@sebakerckhof
Copy link
Contributor

I've mentioned this earlier as part of this problem: #4497 (step 2 in the latest comment)

However, this seems to be the intended behavior for certain flows. E.g. the oauth flow from meteor tool, which only adds the credentialtoken to the query state. But then still, it is a bit weird that an error is displayed in the console.

@psy21d
Copy link
Author

psy21d commented Jul 29, 2015

Need to check BASE64 string encoding, and if it is not, return clean string.

@sebakerckhof
Copy link
Contributor

It actually does this, but further down the road.

So basically it tries to base64 decode and if this fails, the OAuth._stateFromQuery will throw, which is usually caught in the calling function (e.g. in OAuth._credentialTokenFromQuery), which thens return the clean string (which is the credential token) instead.

So this seems to be correct behavior, but it's a bit weird that this is being done by throwing and logging errors.

@psy21d
Copy link
Author

psy21d commented Jul 29, 2015

But there is not fails and fails later!!
Bad situation. Maybe need to create settings (options) way for OAUTH services?

@psy21d
Copy link
Author

psy21d commented Jul 30, 2015

Not weird at all, because it is server console.
Throws and crutches is not proper way where can make a real checking.

@psy21d
Copy link
Author

psy21d commented Jul 30, 2015

Whats-a-problem to write properly code? Need to fix it!

How I can make pull request?

HNWASaivraqvc3Dk4 is-not-a Base64 string, so simply to check it.
Why you to write try-catch dummies when have a full specification
Your code SIMPLY NOT WORK as need!!

"HNWASaivraqvc3Dk4".length 
17

https://en.wikipedia.org/wiki/Base64
MUST to read.
Use ONLY specification and RFC!

NOT STUPID try-catch,
it is unprofessional to shift responsibility on "something", "further down the road.". No, does not! Its just because was written dummies!

Many people caught this error and "was made nice code and thats work proper"? Actually not.

No, does it not work how need.
I am a beginner, I am no right to prove, but understand it is not operating properly, even to me it's obvious.

Instead, changes in the two lines code we are Arguing. What For?
https://en.wikipedia.org/wiki/Base64

Meteor is big and expensive project and yes, code must be orderly and straight.

Thank you for understanding!

@psy21d
Copy link
Author

psy21d commented Jul 30, 2015

Pull Request:
on line 66 then:

OAuth._stateFromQuery = function (query) {
  var string;
    var re = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
    if (re.exec(query.state)) {
        string = new Buffer(query.state, 'base64').toString('binary');
    }  else {
        return query.state;
    }
  try {
    return JSON.parse(string);
  } catch (e) {
    //Log.warn('Unable to parse state from OAuth query: ' + string);
    //Log.warn('returned ' + query.state);
    return query.state;
  }
};

@psy21d
Copy link
Author

psy21d commented Jul 30, 2015

so, this code works good.
line 99:

OAuth._credentialTokenFromQuery = function (query) {
  var state;
  // For backwards-compatibility for older clients, catch any errors
  // that result from parsing the state parameter. If we can't parse it,
  // assume that the state parameter's value is the credential token, as
  // it used to be for older clients.
  try {
    state = OAuth._stateFromQuery(query);
  } catch (err) {
    return query.state;  // there is
  }
  return state.credentialToken;
};

Problem closed.

@psy21d psy21d closed this as completed Jul 30, 2015
@stubailo
Copy link
Contributor

stubailo commented Aug 4, 2015

@psy21d if you would like to submit a Pull Request on GitHub so that we can review and consider merging, follow these directions: https://help.github.com/articles/using-pull-requests/

@adamgins
Copy link

adamgins commented May 9, 2017

related issue #8678

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants