-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(security): upgrade express-jwt to v8.4.1
Fixes/changes that needed to be done in order to make the upgrade work: 1. The HTTP verbs for exempted endpoints are now specified both as lowercase and uppercase meaning that if a specific endpoint is configured to be exempt from JWT authorization then it's method will be specified twice, once as 'POST' and once as 'post' because the underlying library (which is called express-unless) does not have the ability to handle verbs in a case insensitive way. 2. In the registerWebServiceEndpoint function, the configuration of the express-jwt-authz library had to be changed because the scope enforcement was broken due to express-jwt changing the default request property where it places the decoded JWT payload from `"user"` to `"auth"` and this made it incompatible by default with the behavior of express-jwt-authz Luckily there is a parameter to set the request property name and that is now being specified explicitly as `"auth"` so that they are playing nice with each other once again and the authorization's scope based access control works just fine. Fixes #2231 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
18 changed files
with
1,552 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/cactus-cmd-api-server/src/main/typescript/authzn/i-authorization-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...ges/cactus-cmd-api-server/src/main/typescript/authzn/is-express-jwt-options-type-guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { Strings } from "@hyperledger/cactus-common"; | ||
import { Options } from "express-jwt"; | ||
import { Params } from "express-jwt"; | ||
|
||
export function isExpressJwtOptions(x: unknown): x is Options { | ||
export function isExpressJwtOptions(x: unknown): x is Params { | ||
return ( | ||
!!x && | ||
typeof x === "object" && | ||
Array.isArray((x as Options).algorithms) && | ||
Strings.isString((x as Options).secret) | ||
Array.isArray((x as Params).algorithms) && | ||
Strings.isString((x as Params).secret) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/cactus-common/src/main/typescript/authzn/i-jose-fitting-jwt-params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This interface is defined as the lowest common denominator between | ||
* two different types that libraries use that are related to each other. | ||
* The libraries are: `jose` and `express-jwt`. | ||
* | ||
* Why though? | ||
* We need this because when we are using `jose` to sign a JWT payload, | ||
* we are extracting the parameters from a `Params` typed object (which | ||
* is defined as a type by `express-jwt`) and the two have certain | ||
* incompatibilities by default that would either force us to do | ||
* unsafe casts or (the better solution) to do runtime checks. Said | ||
* runtime checks is what this interface is powering through a user- | ||
* defined type-guard. | ||
* | ||
* The list of properties on this interface is incomplete, but that is | ||
* by design because we just want to use it to check whether objects | ||
* are compliant or not with the expectations of the `jose` library for | ||
* JWT signing. | ||
* | ||
* @link https://www.npmjs.com/package/express-jwt | ||
* @link https://www.npmjs.com/package/jose | ||
* @link https://www.rfc-editor.org/rfc/rfc7519 | ||
*/ | ||
export interface IJoseFittingJwtParams { | ||
[key: string]: unknown; | ||
readonly issuer: string; | ||
readonly audience: string; | ||
} | ||
|
||
/** | ||
* User defined type-guard to check/enforce at runtime if an object has | ||
* the shape it needs to for it to be used by the `jose` library for | ||
* parameters to a JWT signing operation. | ||
* | ||
* @param x Literally anything, ideally a IJoseFittingJwtParams shaped | ||
* object. | ||
* @returns Whether x is conformant (at runtime) to the expected type. | ||
*/ | ||
export function isIJoseFittingJwtParams( | ||
x: unknown, | ||
): x is IJoseFittingJwtParams { | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.