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

Changes in OAuth2_Storage_Pdo #7

Closed
wants to merge 1 commit into from
Closed

Conversation

mjamado
Copy link

@mjamado mjamado commented Nov 27, 2012

Better PDO usage (bindParam in several places, including some really insecure ones) and more user table related customization (most of the time, the user table is already done for the platform).

Better PDO usage (bindParam in several places, including some really insecure ones) and more user table related customization (most of the time, the user table is already done for the platform).
), $config);
}

/* ClientCredentialsInterface */
public function checkClientCredentials($client_id, $client_secret = null)
{
$stmt = $this->db->prepare(sprintf('SELECT * from %s where client_id = "%s"', $this->config['client_table_name'], $client_id));
$stmt = $this->db->prepare('SELECT * FROM ' . $this->config['client_table_name'] . ' WHERE client_id = :client_id');
$stmt->bindParam(':client_id', $client_id, PDO::PARAM_STR);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the indentation off here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-paste issue (tabs vs. spaces)

@bshaffer
Copy link
Owner

Thank you for submitting this pull request!

the PDO->execute statement binds the parameters in the same way that bindParam does, it simply uses PDO::PARAM_STRING as a default (see the docs)

So that being the case, how are these changes more secure?

@mjamado
Copy link
Author

mjamado commented Nov 28, 2012

The real security issues were on statements that had something like client_id = "%s" with sprintf. That just gave me the creeps. If someone had sent " OR 1=1 -- or worst in client_id, we would be in serious trouble.

In queries where user_id is used, and because of that int-or-string control, it's just a little more hardened to use PARAM_INT.

The rest was only for consistency sake.

@bshaffer
Copy link
Owner

As stated in my inline comment, there is no security benefit of string concatenation over sprintf. Also, we don't need to worry about sql injection on table names, as that should NEVER be left up to user input. As for username/password sql injection, these are open to sql injection attacks, but as we are binding those in the execute statements, sql injection is not possible.

Since this class is NOT for production use (I will add a comment saying as much... and I apologize for the confusion) the user_id enhancement is not desirable. It is meant to be a proof-of-concept / tracer bullet / whathaveyou.

Thanks for your support!

@bshaffer bshaffer closed this Nov 28, 2012
@mjamado
Copy link
Author

mjamado commented Nov 28, 2012

As I said, string concatenation was only a panic option, and then my coding style took over; the real security issue was inline insertion of parameters, as in line 45, for example. There's nothing wrong with the sprintf (or string concatenation, for all that matters), as long as there's no direct parameter insertion.

This is not production ready; but it could be. Then, all it could take was the override of the password check, and that was it.

@xantrix
Copy link

xantrix commented Dec 17, 2012

Is it possible to change the visibility of properties in "protected" ? To easy extend functionality ?

@bshaffer
Copy link
Owner

If there is a convincing reason to do so, then yes. However, any time a property or method goes from private to public, or public to protected, you are adding entrypoints into your model. This makes it very hard to refactor later, as anything might break backwards compatibility depending on how its used. For this reason, it's best for things to default to private and move to public only if there's a reason.

Which properties do you think should be protected and why? Also, this should be a new thread...

@xantrix
Copy link

xantrix commented Dec 18, 2012

Thanks for your answer.
I would like to override method "getUser($username)" using $db property in my extended class.
But I can find a workaround ;)

@bshaffer
Copy link
Owner

sounds reasonable! Will you send me a pull request?

@xantrix
Copy link

xantrix commented Dec 19, 2012

I have sorted out but I will send you a request. Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants