Skip to content

Commit

Permalink
[@dhealthdapps/backend] fix(routes): fix cookie encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
kravchenkodhealth authored and evias committed Jan 3, 2023
1 parent 0241c69 commit cd34714
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions runtime/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
"@nestjs/config": "^2.0.1",
"@nestjs/core": "^8.0.0",
"@nestjs/event-emitter": "^1.3.1",
"@nestjs/websockets": "^8.0.0",
"@nestjs/platform-ws": "^8.0.0",
"@nestjs/jwt": "^8.0.1",
"@nestjs/mongoose": "^9.1.0",
"@nestjs/passport": "^8.2.2",
"@nestjs/platform-express": "^8.0.0",
"@nestjs/platform-ws": "^8.0.0",
"@nestjs/schedule": "^2.0.1",
"@nestjs/swagger": "^5.2.1",
"@nestjs/websockets": "^8.0.0",
"axios": "^0.27.2",
"cookie-parser": "^1.4.6",
"cron": "^2.0.0",
Expand All @@ -90,6 +90,7 @@
"@nestjs/cli": "^8.0.0",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.0",
"@types/cookie": "^0.5.1",
"@types/cookie-parser": "^1.4.3",
"@types/cron": "^2.0.0",
"@types/express": "^4.17.13",
Expand All @@ -100,6 +101,7 @@
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"cookie": "^0.5.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
Expand Down
13 changes: 12 additions & 1 deletion runtime/backend/src/common/gateways/BaseGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
MessageBody,
} from "@nestjs/websockets";
import { Server } from "https";
import { JwtService } from "@nestjs/jwt";
import cookie from "cookie";
import cookieParser from "cookie-parser";

// internal dependencies
import dappConfigLoader from "../../../config/dapp";
Expand Down Expand Up @@ -49,11 +50,21 @@ export abstract class BaseGateway
async handleConnection(ws: any, req: any) {
// const challenge = this.getChallengeFromUrl(client);
// this.clients.push(challenge);
console.log(req.headers.cookie);

const cookies = req.headers.cookie.split(";");
const challenge = cookies.find((cookie: string) =>
cookie.trim().includes("challenge"),
);

const c: any = cookie.parse(req.headers.cookie);
const decoded = cookieParser.signedCookie(
decodeURIComponent(c.challenge),
process.env.SECURITY_AUTH_TOKEN_SECRET,
);

console.log({ decoded });

this.clients.push(challenge.split("=")[1]);
ws.challenge = challenge;

Expand Down
2 changes: 1 addition & 1 deletion runtime/backend/src/common/routes/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class AuthController {
response.cookie("challenge", authChallenge, {
httpOnly: true,
domain: authCookie.domain,
signed: false,
signed: true,
});

// serves the authentication challenge
Expand Down

0 comments on commit cd34714

Please sign in to comment.