-
Notifications
You must be signed in to change notification settings - Fork 192
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
ARC-1355 add jwt cookie #1234
ARC-1355 add jwt cookie #1234
Changes from all commits
a731465
8f1e91c
c46150f
c24859f
2d7d745
6d7b46b
6f986dc
e10ef25
9a8d091
f6f6b41
fa7a3ae
bccbaed
2848d9d
93d9b98
a3d5c0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { NextFunction, Request, Response } from "express"; | |
import { envVars } from "config/env"; | ||
import { queryAtlassianConnectPublicKey } from "./query-atlassian-connect-public-key"; | ||
import { includes, isEmpty } from "lodash"; | ||
import { booleanFlag, BooleanFlags } from "../../config/feature-flags"; | ||
|
||
const JWT_PARAM = "jwt"; | ||
const AUTH_HEADER = "authorization"; // the header name appears as lower-case | ||
|
@@ -28,18 +29,22 @@ export enum TokenType { | |
context = "context" | ||
} | ||
|
||
export function extractJwtFromRequest(req: Request): string | undefined { | ||
const tokenInQuery = req.query?.[JWT_PARAM]; | ||
let secureJiraHostInCookies; | ||
|
||
|
||
function extractJwtFromRequest(req: Request): string | undefined { | ||
|
||
// JWT appears in both parameter and body will result query hash being invalid. | ||
booleanFlag(BooleanFlags.SECURE_JIRAHOST_IN_COOKIES, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to change the whole chain to be async @mboudreau cause it is pretty long. |
||
.then(flag=>secureJiraHostInCookies = flag); //ignore error | ||
|
||
const tokenInQuery = req.query?.[JWT_PARAM]; | ||
const tokenInBody = req.body?.[JWT_PARAM]; | ||
if (tokenInQuery && tokenInBody) { | ||
req.log.info("JWT token can only appear in either query parameter or request body."); | ||
return; | ||
} | ||
let token = tokenInQuery || tokenInBody; | ||
|
||
// if there was no token in the query-string then fall back to checking the Authorization header | ||
const authHeader = req.headers?.[AUTH_HEADER]; | ||
if (authHeader?.startsWith("JWT ")) { | ||
if (token) { | ||
|
@@ -50,6 +55,13 @@ export function extractJwtFromRequest(req: Request): string | undefined { | |
} | ||
} | ||
|
||
if (!token && secureJiraHostInCookies) { | ||
token = req.cookies?.[JWT_PARAM]; | ||
if (token) { | ||
req.log.info("JWT token found in cookies (last resort)"); | ||
} | ||
} | ||
|
||
// JWT is missing in query and we don't have a valid body. | ||
if (!token) { | ||
req.log.info("JWT token is missing in the request"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { Installation } from "models/installation"; | |
import { NextFunction, Request, Response } from "express"; | ||
import { sendError, TokenType, verifySymmetricJwtTokenMiddleware } from "../jira/util/jwt"; | ||
|
||
const verifyJiraJwtMiddleware = (tokenType: TokenType) => async ( | ||
export const verifyJiraJwtMiddleware = (tokenType: TokenType) => async ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be exported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we kinda need that... |
||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This var will bleed between different requests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what we want :) Once the FF is on, the value will eventually be updated (2nd call after the flip). Given the distributed nature of feature-flags, this is OK imho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, understand that, and the full story is:
turning middleware async
vshave a global var
here, the latter one is less risky.Unless you think there's still impact on this global var?