Skip to content

Instantly share code, notes, and snippets.

@mago0
Created April 10, 2017 21:52
Show Gist options
  • Save mago0/9668b7a71f6317b632d1ea63be8a2888 to your computer and use it in GitHub Desktop.
Save mago0/9668b7a71f6317b632d1ea63be8a2888 to your computer and use it in GitHub Desktop.
rewrite php session id cookie
var gor = require("goreplay_middleware");
gor.init();
let sessionMap = {};
gor.on("request", function(req) {
// Don't replay health-checks
if (gor.httpPath(req.http) != '/ping') {
let session = gor.httpCookie(req.http, "PHPSESSID");
// If the session is already in the map, it's been reassigned to the new ID
// and we'll rewrite the cookie to the new value
if (session && sessionMap[session]) {
req.http = gor.setHttpCookie(req.http, "PHPSESSID", sessionMap[session]);
}
// Search for the Set-Cookie in the original and replayed response. If found, map the original
// response PHPSESSID to the replayed response PHPSESSID for all subsequent requests using the cookie
gor.searchResponses(req.ID, "Set-Cookie: PHPSESSID=(\w+);", function(respSession, replSession) {
console.error(`'MATCH-FOUND: ${respSession}, ${replSession}'`);
if (respSession && replSession) {
sessionMap[respSession] = replSession;
}
})
return req;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment