Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/hub/proxy/strip-remember-me-cookie.ts
Views: 687
/*1In the interest of security and "XSS", we strip the "remember_me" cookie2from the header before passing anything along via the proxy.3The reason this is important is that it's critical that the project (and4nothing running in the project) can get access to a user's auth cookie.5I.e., malicious code running in a project shouldn't be able to steal6auth credentials for all users of a project!7*/89import {10REMEMBER_ME_COOKIE_NAME,11API_COOKIE_NAME,12} from "@cocalc/backend/auth/cookie-names";1314export default function stripRememberMeCookie(cookie): {15cookie: string;16remember_me: string | undefined; // the value of the cookie we just stripped out.17api_key: string | undefined;18} {19if (cookie == null) {20return { cookie, remember_me: undefined, api_key: undefined };21} else {22const v: string[] = [];23let remember_me: string | undefined = undefined;24let api_key: string | undefined = undefined;25for (const c of cookie.split(";")) {26const z = c.split("=");27if (z[0].trim() == REMEMBER_ME_COOKIE_NAME) {28// save it but do not include it in v, which will29// be the new cookies values after going through30// the proxy.31remember_me = z[1].trim();32} else if (z[0].trim() == API_COOKIE_NAME) {33api_key = z[1].trim();34} else {35v.push(c);36}37}38return { cookie: v.join(";"), remember_me, api_key };39}40}414243