Skip to content

Commit e7fa292

Browse files
authored
feat: forward cookies for anti-csrf measures (#133)
See ory/kratos#1458
1 parent b5fb5cf commit e7fa292

8 files changed

+32
-31
lines changed

package-lock.json

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"homepage": "https://github.com/ory/kratos-selfservice-ui-node#readme",
2424
"dependencies": {
25-
"@ory/kratos-client": "^0.0.0-next.d19a7ce5765d",
25+
"@ory/kratos-client": "^0.0.0-next.ffe42eb0cc58",
2626
"@types/axios": "^0.14.0",
2727
"@types/cookie-parser": "^1.4.2",
2828
"@types/express": "^4.17.7",

src/routes/dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default (req: Request, res: Response) => {
7070

7171
const ai = authInfo(req as UserRequest)
7272

73-
kratos.createSelfServiceLogoutUrlForBrowsers(req.cookies['ory_kratos_session']).then(({data}) => {
73+
kratos.createSelfServiceLogoutUrlForBrowsers(req.header('Cookie')).then(({data}) => {
7474
res.render('dashboard', {
7575
session: ai.claims.session,
7676
token: ai,

src/routes/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default (
4242
return;
4343
}
4444

45-
return kratos.getSelfServiceLoginFlow(flow)
45+
return kratos.getSelfServiceLoginFlow(flow, req.header('cookie'))
4646
.then(({ status, data: flow, ...response }) => {
4747
if (status !== 200) {
4848
return Promise.reject(flow);

src/routes/recovery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default (req: Request, res: Response, next: NextFunction) => {
1717
}
1818

1919
kratos
20-
.getSelfServiceRecoveryFlow(flow)
20+
.getSelfServiceRecoveryFlow(flow, req.header('Cookie'))
2121
.then(({ status, data: flow }) => {
2222
if (status !== 200) {
2323
return Promise.reject(flow);

src/routes/registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default (
4444
return;
4545
}
4646

47-
kratos.getSelfServiceRegistrationFlow(flow)
47+
kratos.getSelfServiceRegistrationFlow(flow, req.header('Cookie'))
4848
.then(({ status, data: flow }) => {
4949
if (status !== 200) {
5050
return Promise.reject(flow);

src/routes/settings.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NextFunction, Request, Response } from 'express';
22
import config from '../config';
3-
import { AdminApi, Configuration, PublicApi } from '@ory/kratos-client';
3+
import { Configuration, PublicApi } from '@ory/kratos-client';
44
import { isString, redirectOnSoftError } from '../helpers/sdk';
55

66
// Variable config has keys:
@@ -18,8 +18,7 @@ import { isString, redirectOnSoftError } from '../helpers/sdk';
1818
// public: 'https://ory-kratos-public.example-org.vpc',
1919
// },
2020

21-
const kratosPublic = new PublicApi(new Configuration({ basePath: config.kratos.public }));
22-
const kratosAdmin = new AdminApi(new Configuration({ basePath: config.kratos.admin }));
21+
const kratos = new PublicApi(new Configuration({ basePath: config.kratos.public }));
2322

2423
const settingsHandler = (req: Request, res: Response, next: NextFunction) => {
2524
const flow = req.query.flow;
@@ -31,9 +30,11 @@ const settingsHandler = (req: Request, res: Response, next: NextFunction) => {
3130
return;
3231
}
3332

34-
kratosPublic.createSelfServiceLogoutUrlForBrowsers(req.cookies['ory_kratos_session']).then(({ data }) => {
35-
kratosAdmin
36-
.getSelfServiceSettingsFlow(flow)
33+
console.log(req.header('cookie'));
34+
35+
kratos.createSelfServiceLogoutUrlForBrowsers(req.header('Cookie')).then(({ data }) => {
36+
kratos
37+
.getSelfServiceSettingsFlow(flow, undefined, req.header('Cookie'))
3738
.then(({ status, data: flow }) => {
3839
if (status !== 200) {
3940
return Promise.reject(flow);

src/routes/verification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default (req: Request, res: Response, next: NextFunction) => {
1717
}
1818

1919
kratos
20-
.getSelfServiceVerificationFlow(flow)
20+
.getSelfServiceVerificationFlow(flow,req.header('Cookie'))
2121
.then(({ status, data: flow }) => {
2222
if (status != 200) {
2323
return Promise.reject(flow);

0 commit comments

Comments
 (0)