Skip to content

Conversation

@hmic
Copy link
Contributor

@hmic hmic commented Apr 28, 2017

Only add the default Alg HS256 if none are provided in the custom config, the array gets merged deep, so any default value set will be available whatever gets set from the config (in addition to it).
This is a serve security thread: When setting RS256 it's possible to make up a new token with the public key only that would verify with the HS256 algo!

hmic added 3 commits April 28, 2017 11:51
Only add the default Alg HS256 if none are provided in the custom config, the array gets merged deep, so any default value set will be available whatever gets set from the config (in addition to it).
This is a serve security thread: When setting RS256 it's possible to make up a new token with the public key only that would verify with the HS256 algo!
@codecov
Copy link

codecov bot commented Apr 28, 2017

Codecov Report

Merging #54 into master will increase coverage by 0.32%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #54      +/-   ##
============================================
+ Coverage     94.11%   94.44%   +0.32%     
- Complexity       21       24       +3     
============================================
  Files             1        1              
  Lines            51       54       +3     
============================================
+ Hits             48       51       +3     
  Misses            3        3
Impacted Files Coverage Δ Complexity Δ
src/Auth/JwtAuthenticate.php 94.44% <100%> (+0.32%) 24 <0> (+3) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c010113...ef1890c. Read the comment docs.

'key' => null,
]);

if (!array_key_exists('allowedAlgs', $config) || empty($config['allowedAlgs'])) {
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't just the empty() check suffice?

@hmic
Copy link
Contributor Author

hmic commented May 30, 2017

If you want to see warnings about a non-existant key...

@ADmad
Copy link
Owner

ADmad commented May 30, 2017

Tests please.

{
$key = 'my-custom-key';
$auth = new JwtAuthenticate($this->Registry, [
'allowedAlgs' => 'RS256',
Copy link
Owner

Choose a reason for hiding this comment

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

Setting 'allowedAlgs' to string would have overwritten the default array value even before this patch :) The merging happens when it's an array and that's what needs to be checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True :-/

@ADmad
Copy link
Owner

ADmad commented May 31, 2017

If you want to see warnings about a non-existant key...

How so? We basically need to check if user have provided 'allowedAlgs' in $config and if so don't set the default value. So empty($config['allowedAlgs']) should suffice for that.

ADmad added a commit that referenced this pull request May 31, 2017
@ADmad
Copy link
Owner

ADmad commented May 31, 2017

Fixed in c87d7c4. Thanks.

@ADmad ADmad closed this May 31, 2017
ADmad added a commit that referenced this pull request May 31, 2017
ADmad added a commit that referenced this pull request May 31, 2017
@hmic
Copy link
Contributor Author

hmic commented May 31, 2017

I think the testcase I have added is of value too, as it makes sure the wrong algo fails!

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.

2 participants