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

JFROG refresh token rule #475

Merged
merged 6 commits into from
Dec 13, 2023
Merged

JFROG refresh token rule #475

merged 6 commits into from
Dec 13, 2023

Conversation

babenek
Copy link
Contributor

@babenek babenek commented Dec 8, 2023

Description

Please include a summary of the change and which is fixed.

  • Add JFrog refresh token pattern anf filter

How has this been tested?

Please describe the tests that you ran to verify your changes.

@babenek babenek marked this pull request as ready for review December 8, 2023 12:01
@babenek babenek requested a review from a team as a code owner December 8, 2023 12:01
@codecov-commenter
Copy link

codecov-commenter commented Dec 8, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (6b78cf2) 90.73% compared to head (ca2d85c) 90.72%.

Files Patch % Lines
credsweeper/filters/value_jfrog_token_check.py 88.88% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #475      +/-   ##
==========================================
- Coverage   90.73%   90.72%   -0.01%     
==========================================
  Files         125      126       +1     
  Lines        4252     4280      +28     
  Branches      674      679       +5     
==========================================
+ Hits         3858     3883      +25     
- Misses        261      262       +1     
- Partials      133      135       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +16 to +17
# reftkn:01:0123456789:abcdefGhijklmnoPqrstuVwxyz0
self._pattern = re.compile(r"reftkn:\d+:\d+:[\w_/+-]+")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we sure it is refresh token of Jfrog only with this pattern?
I don't know well, but reftkn can be used other cases also..
If you know about the Jfrog token please let me know.

Copy link
Contributor Author

@babenek babenek Dec 11, 2023

Choose a reason for hiding this comment

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

I assume, the decoded data matched for the pattern is the token type.
At least, the provider encodes their token with the approach.
Unfortunately, there is no info what's structure inside must be. Suppose, last part must have strong entropy.
https://jfrog.com/help/r/platform-api-key-deprecation-and-the-new-reference-tokens/what-is-a-reference-token

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems reference token.. not refresh token.
I think refresh token is more close with below link.
https://jfrog.com/help/r/jfrog-rest-apis/refresh-token

As I understood, refresh token can refresh the access token even if i don't have access token.
So yes, it is credential, but there is no clue of this refresh token's structure..
Could you check this more?

@babenek babenek requested a review from csh519 December 12, 2023 08:38
Comment on lines +45 to +47
# the check only for correct size decoding
if 54 == len(decoded):
# API key (deprecated) - a good integrity check solution was not found
Copy link
Collaborator

@csh519 csh519 Dec 13, 2023

Choose a reason for hiding this comment

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

Could you please explain why 54 is used for the check?
Following your mail there is only limited information on link.
https://github.com/jfrog/build-info/blob/17ba6912ab9cacea83defea1ca2dbd5fd4ab53e7/build-info-extractor/src/main/java/org/jfrog/build/extractor/packageManager/PackageManagerUtils.java#L24

There are some prefixes and minimal lengths, but nothing about 54..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

54 is length of decoded bytes. All tokens i found (except obviously test-like) are base58 encoding.
There is a lite "validation" in case of wrong encoding - an exception filters the value

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... I can't understand enough...
Each tokens with BASE58 encoding are having more than 73 length and it means decoded strings can have various length.. isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The token type has 73 symbols length which decodes to 54 bytes via base58 (base64 is not acceptable due left 4 bits).
So, my suggestion is the base58 decoding should produce 54 bytes from the token (experience from found tokens).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup BASE58 string which has 73 length is decoded to 54 bytes, but there are not only 73 length of tokens as you can see the JFrog code, it is more than..
So what about change the if condition to <=?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As soon the API key is deprecated, IMO the check was designed for an extension, but it will not realized. So, the size of token now used is exactly 73. bigger size may produce false positives in many base64 encodings. "AKCp" is a short signature unfortunately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay. I got it.
Thank you.

if self._pattern.match(decoded.decode(ASCII)):
# identity token
return False
if value.startswith("AKCp"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I checked the link the prefix from JFrog was AKCp8..
Does it wrong? Actually I already saw other token which you sent by email which starts with AKCpB.
If you have other reason to use AKCp as prefix, please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, i found 3 variants. 2,8,B. Anyway, the "if" is for detecting type of token only. It distinguishes "cmVmdGtuO" prefix and "AKCp".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay I see.

@babenek babenek requested a review from csh519 December 13, 2023 07:00
Copy link
Collaborator

@csh519 csh519 left a comment

Choose a reason for hiding this comment

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

JFrog refresh token detecting rule has been added.

LGTM 👍

Copy link
Contributor

@kmnls kmnls left a comment

Choose a reason for hiding this comment

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

Agree

@babenek babenek merged commit b562a46 into Samsung:main Dec 13, 2023
28 of 29 checks passed
@babenek babenek deleted the bart branch December 13, 2023 15:05
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.

5 participants