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

[wip] add jwt action #1

Closed
wants to merge 4 commits into from

Conversation

EltonLobo07
Copy link
Owner

No description provided.

Copy link
Owner Author

Choose a reason for hiding this comment

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

The strategy I have used to check if the string is a valid jwt is:

  • check if the characters used are valid and the string is divided in three parts (using a regex)
  • since the header is an object with typ and optional algorithm properties, check the header too (using JavaScript)

Something similar was done here but I think the first check with the regex is still needed), do you think it's a good idea?

Choose a reason for hiding this comment

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

I will review this and the 'none' algorithm question after we solved the other questions.

} from '../../types/index.ts';
import { _addIssue } from '../../utils/index.ts';

const POSSIBLE_JWT_REGEX = /^(?:[\w-]+\.){2}[\w-]+$/u;
Copy link
Owner Author

Choose a reason for hiding this comment

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

Usually the regexes are stored inside /library/src/regex.ts. But I think the file is used to only store complete public regexes. By complete I mean if the string passes the regex's test, the string is valid. Like I stated (the comment at the top of this file), this regex is just the first part of the whole check, so its better it is a private member than in /library/src/regex.ts. Also, by naming it POSSIBLE_JWT_REGEX I meant if the string passes the test, there is a possiblity of the string being a valid jwt. If you have a better name for this regex ref, let me know. 

Choose a reason for hiding this comment

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

This looks good to me!

| 'PS256'
| 'PS384'
| 'PS512'
| 'none';
Copy link
Owner Author

Choose a reason for hiding this comment

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

The none algorithm has a problem mentioned here under the title Meet the "None" Algorithm but the algorithm was present in the RFC. I think it we should follow the RFC as we are just checking the structure of the string. I wanted to mention it here to let you know.

| 'PS512'
| 'none';

function isValidJwt(
Copy link
Owner Author

Choose a reason for hiding this comment

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

Would you recommend inlining this function in the requirement function of the implementation? Or is this okay? I think this is better for readability.

Choose a reason for hiding this comment

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

I think I would implement it similar to how creditCard is implemented.

/**
* The algorithm used to sign the jwt.
*/
readonly algorithm: TJwtAlgorithm;
Copy link
Owner Author

Choose a reason for hiding this comment

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

For some actions, there is a requirement property. Initially I concluded, the algorithm can be considered as a requirement but after thinking about it, I decided to add a new key because I think a requirement is something complete. Example: the length action with requirement set to 5 would mean testing the input with the requirement, nothing else. But in this case there are two steps. So, should I use the requirement key? If yes, what value should I set it to? What was the purpose of the requirement key in the issue and action objects?

Choose a reason for hiding this comment

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

I have answered this at the other comment.

/**
* The algorithm used to sign the jwt.
*/
readonly algorithm: TJwtAlgorithm;
Copy link
Owner Author

Choose a reason for hiding this comment

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

Same question mentioned here

Choose a reason for hiding this comment

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

Adding the algorithm parameter as a property to JwtAction looks good to me, but I would not add it to JwtIssue as issues so far only contain common properties. In simple words, we never added additional properties to issues in the past, but we added them to the action itself to make them accessible and allow them to be serialized and dezerialized sometime in the future.

Improvements:
    - remove the `algorithm` property from the `JwtIssue` interface
      so that only common properties are present in the interface
    - add the `requirement` property to `JwtAction` & `JwtIssue`. The
      property is mapped to the jwt validation function
@EltonLobo07
Copy link
Owner Author

Thank you! I think everything is clear from this point, except the strategy used.

My plan:

  1. I'll add tests
  2. review the changes once again (make changes if needed)
  3. create a PR for the main repository
  4. you can review/make changes and merge the action along with the tests
  5. I'll take care of the documentation

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