Skip to content

[Security] [Core] String utils refactor #14028

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

Closed
wants to merge 6 commits into from

Conversation

ircmaxell
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This supersedes #13984 (it includes it, but also includes additional refactoring).

Since length information is leaked in any case, preventing unnecessary duplication of secrets is important. Since casting will always make a copy, we only cast if absolutely necessary. Additionally, appending will create a new copy of the secret, so we avoid doing that, but instead only iterate over the minimum of the two strings.

@sarciszewski
Copy link
Contributor

👍 looks great to me

@ircmaxell ircmaxell changed the title String utils refactor [Security] [Core] String utils refactor Mar 23, 2015

// Extend the known string to avoid uninitialized string offsets
$knownString .= $userInput;
if ($userLen != $knownLen) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong indent?

Copy link
Contributor

Choose a reason for hiding this comment

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

We also prefer strong comparison !==.

@fabpot
Copy link
Member

fabpot commented Mar 24, 2015

Closing in favor of #14024, which includes these changes (it's much easier for everyone to work on one PR).

@fabpot fabpot closed this Mar 24, 2015
@ircmaxell
Copy link
Contributor Author

This makes me sad.

@ircmaxell
Copy link
Contributor Author

@hhamon thanks for the review. If this ever gets re-opened I'll handle the issues. But seeing as it's closed, there's no point.

@fabpot
Copy link
Member

fabpot commented Mar 24, 2015

@ircmaxell Sorry about this. I thought the third PR was really just about getting the changes from your PR and #13984, and then adding on top of it, but I read too fast (just by looking at the commit list.) I apologize for the mistake and I'm reopening this PR.

I'm no security expert and I trust you and @sarciszewski on those matters, so I will let you let me know which one(s) should be merged.

@fabpot fabpot reopened this Mar 24, 2015
fabpot added a commit that referenced this pull request Mar 25, 2015
…rcmaxell)

This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #14028).

Discussion
----------

[Security] [Core] String utils refactor

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This supersedes #13984 (it includes it, but also includes additional refactoring).

Since length information is leaked in any case, preventing unnecessary duplication of secrets is important. Since casting will *always* make a copy, we only cast if absolutely necessary. Additionally, appending will create a new copy of the secret, so we avoid doing that, but instead only iterate over the minimum of the two strings.

Commits
-------

45cfb44 Change behavior to mirror hash_equals() returning early if there is a length mismatch
8269589 CS fixing
bdea4ba Prevent modifying secrets as much as possible
76b36d3 Update StringUtils.php
7221efc Whitespace
56ed71c Update StringUtils.php
@fabpot
Copy link
Member

fabpot commented Mar 25, 2015

I've merged this PR in the 2.3 branch (I've fixed the CS in 2c67400). Thank you @ircmaxell and sorry for the confusion yesterday.

@fabpot fabpot closed this Mar 25, 2015
@sarciszewski
Copy link
Contributor

👍 glad to see this resolved in days rather than months :)

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

Successfully merging this pull request may close these issues.

6 participants