1
|
/**
|
2
|
* part of Hachette
|
3
|
* Filtering request headers to remove hachette cookies that might have slipped
|
4
|
* through.
|
5
|
*
|
6
|
* Copyright (C) 2021 Wojtek Kosior
|
7
|
* Redistribution terms are gathered in the `copyright' file.
|
8
|
*/
|
9
|
|
10
|
/*
|
11
|
* IMPORTS_START
|
12
|
* IMPORT extract_signed
|
13
|
* IMPORTS_END
|
14
|
*/
|
15
|
|
16
|
function is_valid_hachette_cookie(cookie)
|
17
|
{
|
18
|
const match = /^hachette-(\w*)=(.*)$/.exec(cookie);
|
19
|
if (!match)
|
20
|
return false;
|
21
|
|
22
|
return !extract_signed(match.slice(1, 3)).fail;
|
23
|
}
|
24
|
|
25
|
function remove_hachette_cookies(header)
|
26
|
{
|
27
|
if (header.name !== "Cookie")
|
28
|
return header;
|
29
|
|
30
|
const cookies = header.value.split("; ");
|
31
|
const value = cookies.filter(c => !is_valid_hachette_cookie(c)).join("; ");
|
32
|
|
33
|
return value ? {name: "Cookie", value} : null;
|
34
|
}
|
35
|
|
36
|
function filter_cookie_headers(headers)
|
37
|
{
|
38
|
return headers.map(remove_hachette_cookies).filter(h => h);
|
39
|
}
|
40
|
|
41
|
/*
|
42
|
* EXPORTS_START
|
43
|
* EXPORT filter_cookie_headers
|
44
|
* EXPORTS_END
|
45
|
*/
|