Random strings for cookie values (#1122)

This commit is contained in:
SpedNSFW
2021-02-23 13:40:43 +11:00
committed by GitHub
parent 14230d7b52
commit acbdee76de
5 changed files with 60 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/chromedp/chromedp"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/utils"
)
// set cookies for the native http client
@@ -32,7 +33,7 @@ func setCookies(jar *cookiejar.Jar, scraperConfig config) {
for _, cookie := range ckURL.Cookies {
httpCookie = &http.Cookie{
Name: cookie.Name,
Value: cookie.Value,
Value: getCookieValue(cookie),
Path: cookie.Path,
Domain: cookie.Domain,
}
@@ -53,6 +54,13 @@ func setCookies(jar *cookiejar.Jar, scraperConfig config) {
}
}
func getCookieValue(cookie *scraperCookies) string {
if cookie.ValueRandom > 0 {
return utils.RandomSequence(cookie.ValueRandom)
}
return cookie.Value
}
// print all cookies from the jar of the native http client
func printCookies(jar *cookiejar.Jar, scraperConfig config, msg string) {
driverOptions := scraperConfig.DriverOptions
@@ -92,7 +100,7 @@ func setCDPCookies(driverOptions scraperDriverOptions) chromedp.Tasks {
for _, ckURL := range driverOptions.Cookies {
for _, cookie := range ckURL.Cookies {
success, err := network.SetCookie(cookie.Name, cookie.Value).
success, err := network.SetCookie(cookie.Name, getCookieValue(cookie)).
WithExpires(&expr).
WithDomain(cookie.Domain).
WithPath(cookie.Path).