Path: blob/master/src/packages/hub/proxy/strip-remember-me-cookie.ts
1496 views
/*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 {21cookie,22remember_me: undefined,23api_key: undefined,24};25} else {26const v: string[] = [];27let remember_me: string | undefined = undefined;28let api_key: string | undefined = undefined;29for (const c of cookie.split(";")) {30const z = c.split("=");31if (z[0].trim() == REMEMBER_ME_COOKIE_NAME) {32// save it but do not include it in v, which will33// be the new cookies values after going through34// the proxy.35remember_me = z[1].trim();36} else if (z[0].trim() == API_COOKIE_NAME) {37api_key = z[1].trim();38} else {39v.push(c);40}41}42return { cookie: v.join(";"), remember_me, api_key };43}44}454647