Created
June 27, 2019 15:05
-
-
Save ccapndave/61efbe7213d426d96d8f2e9da850dec4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function monkeyPatchXMLHttpRequest() { | |
const { xhook } = require("xhook"); | |
xhook.before(function (request) { | |
if (request.headers[ "X-Passphrase" ]) { | |
request.passphrase = request.headers[ "X-Passphrase" ]; | |
delete request.headers[ "X-Passphrase" ]; | |
} | |
}); | |
xhook.after(async function (request, response, callback) { | |
if (request.passphrase) { | |
try { | |
const plaintext = await Fernet.decrypt(request.passphrase, atob(response.text)); | |
response.text = response.data = plaintext; | |
} catch (e) { | |
response.text = e.message; | |
response.status = 400; | |
response.statusText = e.message; | |
} | |
} | |
callback(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment