Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fuckms-refreshtokensync
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
msc
fuckms-refreshtokensync
Commits
119f329d
There was an error fetching the commit references. Please try again later.
Commit
119f329d
authored
3 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
Allow modifying cookies
parent
7c8e19a4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
background.js
+46
-0
46 additions, 0 deletions
background.js
with
46 additions
and
0 deletions
background.js
+
46
−
0
View file @
119f329d
...
@@ -97,6 +97,29 @@ function storeInBrowserStorage(item, callback_function) {
...
@@ -97,6 +97,29 @@ function storeInBrowserStorage(item, callback_function) {
chrome
.
storage
.
local
.
set
(
item
,
callback_function
);
chrome
.
storage
.
local
.
set
(
item
,
callback_function
);
}
}
/*
* This function set a key-value pair in HTTP header "Cookie",
* and returns the value of HTTP header after modification.
* If key already exists, it modify the value.
* If key doesn't exist, it add the key-value pair.
* If value is undefined, it delete the key-value pair from cookies.
* Recolic K <root@recolic.net>
*/
function
cookie_keyvalues_set
(
original_cookies
,
key
,
value
)
{
let
new_element
=
key
+
"
=
"
+
value
;
// not used if value is undefined.
let
cookies_ar
=
original_cookies
.
split
(
"
;
"
).
filter
(
e
=>
e
.
trim
().
length
>
0
);
let
selected_cookie_index
=
cookies_ar
.
findIndex
(
kv
=>
kv
.
startsWith
(
key
+
"
=
"
));
if
(
selected_cookie_index
==
-
1
)
cookies_ar
.
push
(
new_element
);
else
{
if
(
value
===
undefined
)
cookies_ar
.
splice
(
selected_cookie_index
,
1
);
else
cookies_ar
.
splice
(
selected_cookie_index
,
1
,
new_element
);
}
return
cookies_ar
.
join
(
"
;
"
);
}
/*
/*
* Standard function to log messages
* Standard function to log messages
...
@@ -142,6 +165,29 @@ function rewriteRequestHeader(e) {
...
@@ -142,6 +165,29 @@ function rewriteRequestHeader(e) {
"
for url
"
+
e
.
url
);
"
for url
"
+
e
.
url
);
}
}
}
}
else
if
(
to_modify
.
action
===
"
cookie_add_or_modify
"
)
{
let
header_cookie
=
e
.
requestHeaders
.
find
(
header
=>
header
.
name
.
toLowerCase
()
===
"
cookie
"
);
let
new_cookie
=
cookie_keyvalues_set
(
header_cookie
===
undefined
?
""
:
header_cookie
.
value
,
to_modify
.
header_name
,
to_modify
.
header_value
);
if
(
header_cookie
===
undefined
)
{
e
.
requestHeaders
.
push
({
"
name
"
:
"
Cookie
"
,
"
value
"
:
new_cookie
});
if
(
config
.
debug_mode
)
log
(
"
cookie_add_or_modify new_header : name=Cookie,value=
"
+
new_cookie
+
"
for url
"
+
e
.
url
);
}
else
{
header_cookie
.
value
=
new_cookie
;
if
(
config
.
debug_mode
)
log
(
"
cookie_add_or_modify modify_header : name=Cookie,value=
"
+
new_cookie
+
"
for url
"
+
e
.
url
);
}
}
else
if
(
to_modify
.
action
===
"
cookie_delete
"
)
{
let
header_cookie
=
e
.
requestHeaders
.
find
(
header
=>
header
.
name
.
toLowerCase
()
===
"
cookie
"
);
let
new_cookie
=
cookie_keyvalues_set
(
header_cookie
===
undefined
?
""
:
header_cookie
.
value
,
to_modify
.
header_name
,
to_modify
.
header_value
);
if
(
header_cookie
===
undefined
)
{
if
(
config
.
debug_mode
)
log
(
"
cookie_delete: no cookie header found. doing nothing for url
"
+
e
.
url
);
}
else
{
header_cookie
.
value
=
new_cookie
;
if
(
config
.
debug_mode
)
log
(
"
cookie_delete modify_header : name=Cookie,value=
"
+
new_cookie
+
"
for url
"
+
e
.
url
);
}
}
}
}
}
}
if
(
config
.
debug_mode
)
log
(
"
End modify request headers for url
"
+
e
.
url
);
if
(
config
.
debug_mode
)
log
(
"
End modify request headers for url
"
+
e
.
url
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment