Skip to content

[Security] Made optimization on constant-time algorithm removing modulus operator #11574

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

Merged
merged 1 commit into from
Aug 31, 2014
Merged

Conversation

yosmanyga
Copy link
Contributor

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

This fix improves the constant-time algorithm used to compare strings, as it removes the % operator inside the loop.

@stof
Copy link
Member

stof commented Aug 8, 2014

Why is it labelled as [Validator] ? It has nothing to do with the valdiator component

// Extend strings to avoid uninitialized string offsets
$tmp = $knownString;
$knownString .= $userInput;
$userInput .= $tmp;
Copy link
Member

Choose a reason for hiding this comment

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

this line is not needed, given we iterate over the user input length, so we will never go further (there is no modulus operator applied when accessing the userInput char in the current implementation either)

@yosmanyga yosmanyga changed the title [Validator] Made optimization on constant-time algorithm removing modulus operator [Security] Made optimization on constant-time algorithm removing modulus operator Aug 14, 2014
@fabpot
Copy link
Member

fabpot commented Aug 28, 2014

👍

1 similar comment
@stof
Copy link
Member

stof commented Aug 28, 2014

👍

@fabpot
Copy link
Member

fabpot commented Aug 31, 2014

Thank you @yosmanyga.

@fabpot fabpot merged commit 000bd0d into symfony:2.3 Aug 31, 2014
fabpot added a commit that referenced this pull request Aug 31, 2014
…removing modulus operator (yosmanyga)

This PR was merged into the 2.3 branch.

Discussion
----------

[Security] Made optimization on constant-time algorithm removing modulus operator

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

This fix improves the constant-time algorithm used to compare strings, as it removes the `%` operator inside the loop.

Commits
-------

000bd0d Made optimization deprecating modulus operator
$knownLen = strlen($knownString);
$userLen = strlen($userInput);

// Extend know string to avoid uninitialized string offsets
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

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.

5 participants