Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3563025
D9290.id32309.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D9290.id32309.diff
View Options
diff --git a/keyserver/src/responders/handlers.js b/keyserver/src/responders/handlers.js
--- a/keyserver/src/responders/handlers.js
+++ b/keyserver/src/responders/handlers.js
@@ -15,16 +15,12 @@
import {
fetchViewerForJSONRequest,
addCookieToJSONResponse,
- fetchViewerForHomeRequest,
addCookieToHomeResponse,
createNewAnonymousCookie,
setCookiePlatformDetails,
} from '../session/cookies.js';
import type { Viewer } from '../session/viewer.js';
-import {
- type AppURLFacts,
- getAppURLFactsFromRequestURL,
-} from '../utils/urls.js';
+import { getAppURLFactsFromRequestURL } from '../utils/urls.js';
import {
policiesValidator,
validateInput,
@@ -59,8 +55,8 @@
req: $Request,
res: $Response,
) => Promise<void>;
-export type HTMLResponder = DownloadResponder;
export type HTTPGetResponder = DownloadResponder;
+export type HTMLResponder = (req: $Request, res: $Response) => Promise<void>;
function jsonHandler(
responder: JSONResponder,
@@ -96,22 +92,10 @@
return;
}
const result = { ...responderResult };
- addCookieToJSONResponse(
- viewer,
- res,
- result,
- expectCookieInvalidation,
- getAppURLFactsFromRequestURL(req.originalUrl),
- );
+ addCookieToJSONResponse(viewer, res, result, expectCookieInvalidation);
res.json({ success: true, ...result });
} catch (e) {
- await handleException(
- e,
- res,
- getAppURLFactsFromRequestURL(req.originalUrl),
- viewer,
- expectCookieInvalidation,
- );
+ await handleException(e, res, viewer, expectCookieInvalidation);
}
};
}
@@ -125,12 +109,7 @@
viewer = await fetchViewerForJSONRequest(req);
await responder(viewer, req, res);
} catch (e) {
- await handleException(
- e,
- res,
- getAppURLFactsFromRequestURL(req.originalUrl),
- viewer,
- );
+ await handleException(e, res, viewer);
}
};
}
@@ -145,11 +124,7 @@
} catch (e) {
// Passing viewer in only makes sense if we want to handle failures as
// JSON. We don't, and presume all download handlers avoid ServerError.
- await handleException(
- e,
- res,
- getAppURLFactsFromRequestURL(req.originalUrl),
- );
+ await handleException(e, res);
}
};
}
@@ -157,7 +132,6 @@
async function handleException(
error: Error,
res: $Response,
- appURLFacts: AppURLFacts,
viewer?: ?Viewer,
expectCookieInvalidation?: boolean,
) {
@@ -187,13 +161,7 @@
viewer.cookieInvalidated = true;
}
// This can mutate the result object
- addCookieToJSONResponse(
- viewer,
- res,
- result,
- !!expectCookieInvalidation,
- appURLFacts,
- );
+ addCookieToJSONResponse(viewer, res, result, !!expectCookieInvalidation);
}
res.json(result);
}
@@ -203,14 +171,13 @@
): (req: $Request, res: $Response) => Promise<void> {
return async (req: $Request, res: $Response) => {
try {
- const viewer = await fetchViewerForHomeRequest(req);
addCookieToHomeResponse(
- viewer,
+ req,
res,
getAppURLFactsFromRequestURL(req.originalUrl),
);
res.type('html');
- await responder(viewer, req, res);
+ await responder(req, res);
} catch (e) {
console.warn(e);
if (!res.headersSent) {
@@ -252,21 +219,10 @@
return;
}
const result = { ...responderResult };
- addCookieToJSONResponse(
- viewer,
- res,
- result,
- false,
- getAppURLFactsFromRequestURL(req.originalUrl),
- );
+ addCookieToJSONResponse(viewer, res, result, false);
res.json({ success: true, ...result });
} catch (e) {
- await handleException(
- e,
- res,
- getAppURLFactsFromRequestURL(req.originalUrl),
- viewer,
- );
+ await handleException(e, res, viewer);
}
};
}
diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js
--- a/keyserver/src/responders/website-responders.js
+++ b/keyserver/src/responders/website-responders.js
@@ -13,7 +13,6 @@
import stores from 'lib/facts/stores.js';
import getTitle from 'web/title/getTitle.js';
-import { Viewer } from '../session/viewer.js';
import { waitForStream } from '../utils/json-stream.js';
import {
getAppURLFactsFromRequestURL,
@@ -111,11 +110,7 @@
}
}
-async function websiteResponder(
- viewer: Viewer,
- req: $Request,
- res: $Response,
-): Promise<void> {
+async function websiteResponder(req: $Request, res: $Response): Promise<void> {
const { basePath } = getAppURLFactsFromRequestURL(req.originalUrl);
const baseURL = basePath.replace(/\/$/, '');
diff --git a/keyserver/src/session/cookies.js b/keyserver/src/session/cookies.js
--- a/keyserver/src/session/cookies.js
+++ b/keyserver/src/session/cookies.js
@@ -558,7 +558,6 @@
viewer: Viewer,
res: $Response,
result: Object,
- appURLFacts: AppURLFacts,
) {
let threadInfos = {},
userInfos = {};
@@ -585,8 +584,6 @@
}
if (viewer.cookieSource === cookieSources.BODY) {
sessionChange.cookie = viewer.cookiePairString;
- } else {
- addActualHTTPCookie(viewer, res, appURLFacts);
}
if (viewer.sessionIdentifierType === sessionIdentifierTypes.BODY_SESSION_ID) {
sessionChange.sessionID = viewer.sessionID ? viewer.sessionID : null;
@@ -755,7 +752,6 @@
res: $Response,
result: Object,
expectCookieInvalidation: boolean,
- appURLFacts: AppURLFacts,
) {
if (expectCookieInvalidation) {
viewer.cookieInvalidated = false;
@@ -764,21 +760,22 @@
handleAsyncPromise(updateCookie(viewer));
}
if (viewer.sessionChanged) {
- addSessionChangeInfoToResult(viewer, res, result, appURLFacts);
- } else if (viewer.cookieSource !== cookieSources.BODY) {
- addActualHTTPCookie(viewer, res, appURLFacts);
+ addSessionChangeInfoToResult(viewer, res, result);
}
}
function addCookieToHomeResponse(
- viewer: Viewer,
+ req: $Request,
res: $Response,
appURLFacts: AppURLFacts,
) {
- if (!viewer.getData().cookieInsertedThisRequest) {
- handleAsyncPromise(updateCookie(viewer));
+ const { user, anonymous } = req.cookies;
+ if (user) {
+ res.cookie(cookieTypes.USER, user, getCookieOptions(appURLFacts));
+ }
+ if (anonymous) {
+ res.cookie(cookieTypes.ANONYMOUS, anonymous, getCookieOptions(appURLFacts));
}
- addActualHTTPCookie(viewer, res, appURLFacts);
}
function getCookieOptions(appURLFacts: AppURLFacts) {
@@ -794,21 +791,6 @@
};
}
-function addActualHTTPCookie(
- viewer: Viewer,
- res: $Response,
- appURLFacts: AppURLFacts,
-) {
- res.cookie(
- viewer.cookieName,
- viewer.cookieString,
- getCookieOptions(appURLFacts),
- );
- if (viewer.cookieName !== viewer.initialCookieName) {
- res.clearCookie(viewer.initialCookieName, getCookieOptions(appURLFacts));
- }
-}
-
async function setCookieSignedIdentityKeysBlob(
cookieID: string,
signedIdentityKeysBlob: SignedIdentityKeysBlob,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 11:26 AM (7 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2726148
Default Alt Text
D9290.id32309.diff (6 KB)
Attached To
Mode
D9290: [keyserver] Stop sending http cookies
Attached
Detach File
Event Timeline
Log In to Comment