@hellocoop/express 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/auth.d.ts +1 -1
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +24 -9
- package/package.json +1 -1
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Auth } from '@hellocoop/types';
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
|
-
export declare const saveAuthCookie: (res: Response, auth: Auth) => Promise<boolean>;
|
|
3
|
+
export declare const saveAuthCookie: (res: Response, auth: Auth, sameSite?: boolean) => Promise<boolean>;
|
|
4
4
|
export declare const clearAuthCookie: (res: Response) => Promise<void>;
|
|
5
5
|
export declare const getAuthfromCookies: (req: Request, res: Response) => Promise<Auth>;
|
|
6
6
|
export declare const NotLoggedIn: Auth;
|
package/dist/lib/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAwB3C,eAAO,MAAM,cAAc,QAAgB,QAAQ,QAAQ,IAAI,aAAY,OAAO,KAAY,QAAQ,OAAO,CAW5G,CAAA;AAED,eAAO,MAAM,eAAe,QAAgB,QAAQ,kBAKnD,CAAA;AAGD,eAAO,MAAM,kBAAkB,QAChB,OAAO,OAAO,QAAQ,KAC3B,QAAQ,IAAI,CA8BrB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,IAA2B,CAAA"}
|
package/dist/lib/auth.js
CHANGED
|
@@ -9,18 +9,24 @@ const config_1 = __importDefault(require("./config"));
|
|
|
9
9
|
const cookie_1 = require("cookie");
|
|
10
10
|
const oidc_1 = require("./oidc");
|
|
11
11
|
const { cookies: { authName, oidcName } } = config_1.default;
|
|
12
|
-
const
|
|
12
|
+
const laxAuthName = 'lax-' + authName;
|
|
13
|
+
const setEncryptedCookie = (res, sameSite, encCookie) => {
|
|
14
|
+
const cookieName = sameSite ? authName : laxAuthName;
|
|
15
|
+
const options = {
|
|
16
|
+
httpOnly: true,
|
|
17
|
+
secure: config_1.default.production,
|
|
18
|
+
path: '/' // let any server side route call getAuth
|
|
19
|
+
};
|
|
20
|
+
if (sameSite)
|
|
21
|
+
options.sameSite = 'strict';
|
|
22
|
+
res.appendHeader('Set-Cookie', (0, cookie_1.serialize)(cookieName, encCookie, options));
|
|
23
|
+
};
|
|
24
|
+
const saveAuthCookie = async (res, auth, sameSite = false) => {
|
|
13
25
|
try {
|
|
14
26
|
const encCookie = await (0, core_1.encryptObj)(auth, config_1.default.secret);
|
|
15
27
|
if (!encCookie)
|
|
16
28
|
return false;
|
|
17
|
-
res
|
|
18
|
-
httpOnly: true,
|
|
19
|
-
secure: config_1.default.production,
|
|
20
|
-
sameSite: 'strict',
|
|
21
|
-
path: '/' // let any server side route call getAuth
|
|
22
|
-
// no maxAge => session cooke
|
|
23
|
-
}));
|
|
29
|
+
setEncryptedCookie(res, sameSite, encCookie);
|
|
24
30
|
return true;
|
|
25
31
|
}
|
|
26
32
|
catch (e) {
|
|
@@ -40,7 +46,16 @@ const getAuthfromCookies = async function (req, res) {
|
|
|
40
46
|
const cookies = (0, cookie_1.parse)(req.headers.cookie || '');
|
|
41
47
|
if (cookies[oidcName]) // clear OIDC cookie it still there
|
|
42
48
|
(0, oidc_1.clearOidcCookie)(res);
|
|
43
|
-
const
|
|
49
|
+
const laxAuthCookie = cookies[laxAuthName];
|
|
50
|
+
if (laxAuthCookie) {
|
|
51
|
+
// rotate to a sameSite:strict cookie
|
|
52
|
+
setEncryptedCookie(res, true, laxAuthCookie);
|
|
53
|
+
res.appendHeader('Set-Cookie', (0, cookie_1.serialize)(laxAuthName, '', {
|
|
54
|
+
expires: new Date(0),
|
|
55
|
+
path: '/', // Specify the path
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
const authCookie = cookies[authName] || laxAuthCookie;
|
|
44
59
|
if (!authCookie)
|
|
45
60
|
return exports.NotLoggedIn;
|
|
46
61
|
try {
|