Skip to content

Commit

Permalink
Possibly fix Humble token escaping (tkashkin#32, tkashkin#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkashkin committed Jan 23, 2019
1 parent c975c2a commit 3dd7dbe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions data/css/themes/elementary.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.titlebar.flat .title,
.titlebar.flat .subtitle,
.titlebar.flat .titlebutton,
.titlebar.flat button,
.titlebar.flat *:not(entry) image
{
color: @textColorPrimaryDefault;
Expand All @@ -20,6 +21,7 @@
.titlebar.flat .title:backdrop,
.titlebar.flat .subtitle:backdrop,
.titlebar.flat .titlebutton:backdrop,
.titlebar.flat button:backdrop,
.titlebar.flat *:not(entry) image:backdrop
{
color: mix(@textColorPrimaryDefault, @titlebar_color, 0.3);
Expand Down
21 changes: 19 additions & 2 deletions src/data/sources/humble/Humble.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ namespace GameHub.Data.Sources.Humble

public string? user_token = null;

public static string? escaped_cookie(string? token)
{
if(token == null)
{
return null;
}
var escaped = "%s=\"%s\";".printf(AUTH_COOKIE, token.replace("=", "\\075"));

if(GameHub.Application.log_auth && GameHub.Application.log_verbose)
{
debug("[Humble.escaped_cookie] Unescaped: %s", token);
debug("[Humble.escaped_cookie] Escaped: %s", escaped);
}

return escaped;
}

private Settings.Auth.Humble settings;

public Humble()
Expand Down Expand Up @@ -88,7 +105,7 @@ namespace GameHub.Data.Sources.Humble

wnd.finished.connect(token =>
{
user_token = token.replace("\"", "");
user_token = token.replace("\"", "").replace("\\\\075", "=").replace("\\075", "=");
settings.access_token = user_token ?? "";
if(GameHub.Application.log_auth)
{
Expand Down Expand Up @@ -146,7 +163,7 @@ namespace GameHub.Data.Sources.Humble
}

var headers = new HashMap<string, string>();
headers["Cookie"] = @"$(AUTH_COOKIE)=\"$(user_token)\";";
headers["Cookie"] = escaped_cookie(user_token);

var orders_json = Parser.load_remote_file("https://www.humblebundle.com/api/v1/user/order?ajax=true", "GET", null, headers);
var orders_md5 = Utils.md5(orders_json);
Expand Down
4 changes: 2 additions & 2 deletions src/data/sources/humble/Trove.vala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace GameHub.Data.Sources.Humble
}

var headers = new HashMap<string, string>();
headers["Cookie"] = @"$(AUTH_COOKIE)=\"$(user_token)\";";
headers["Cookie"] = escaped_cookie(user_token);

var html = Parser.parse_remote_html_file(Trove.PAGE_URL, "GET", null, headers);

Expand Down Expand Up @@ -144,7 +144,7 @@ namespace GameHub.Data.Sources.Humble
public static string? sign_url(string machine_name, string filename, string humble_token)
{
var headers = new HashMap<string, string>();
headers["Cookie"] = @"$(AUTH_COOKIE)=\"$(humble_token)\";";
headers["Cookie"] = escaped_cookie(humble_token);

var data = new HashMap<string, string>();
data["machine_name"] = machine_name;
Expand Down

0 comments on commit 3dd7dbe

Please sign in to comment.