Merge lp:~sil/libubuntuone/restrict-domains into lp:libubuntuone

Proposed by Stuart Langridge
Status: Merged
Approved by: Rodrigo Moya
Approved revision: 72
Merged at revision: not available
Proposed branch: lp:~sil/libubuntuone/restrict-domains
Merge into: lp:libubuntuone
Diff against target: 348 lines (+234/-55)
4 files modified
data/Makefile.am (+2/-0)
data/outside_domain.html (+56/-0)
data/trying_sso.html (+58/-0)
libubuntuone/u1-music-store.c (+118/-55)
To merge this branch: bzr merge lp:~sil/libubuntuone/restrict-domains
Reviewer Review Type Date Requested Status
Rodrigo Moya (community) Approve
Tim Cole (community) Approve
Review via email: mp+22063@code.launchpad.net

Commit message

Trap URLs that lead out of the Music Store (either to the non-U1 7digital.com, or to Ubuntu One authentication URLs) and show an error page instead, along with a way of logging the error in querystrings so that we can identify that it happened.

Description of the change

Trap URLs that lead out of the Music Store (either to the non-U1 7digital.com, or to Ubuntu One authentication URLs) and show an error page instead, along with a way of logging the error in querystrings so that we can identify that it happened.

To post a comment you must log in.
Revision history for this message
Martin Albisetti (beuno) wrote :

59 +<h2>There was a problem with what you just tried to do. Please go back and try something different.</h2>

I'm not sure that's the best error message ever written.

122 +<h2>An error has occurred. Please ensure that your
123 +computer is connected to Ubuntu One.</h2>

How about a link to somewhere explaining how to do that? I guess that would be an external link :)
Can you open up something in firefox though? or explain right there and then?

Revision history for this message
Tim Cole (tcole) wrote :

Looks alright. But it does need a better error message. I'd suggest "The link you clicked is currently unsupported. Please try exploring a different part of the music store."

review: Approve
Revision history for this message
Stuart Langridge (sil) wrote :

beuno: for the latter message, you only get it if the thing that was supposed to open up firefox has failed. This whole branch is there to provide a safety net if there are bugs in the existing code, to stop the user crashing and burning as a result of those bugs. In theory, no-one should ever see the messages.

tcole: I'll change the first one. I was feeling a bit too whimsical when I wrote it :)

72. By Stuart Langridge

slightly less whimsical error message

Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

There are some improvements that can be done on the C code of this branch, but it still is correct as it is, so approving and will add those improvements in other branches

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/Makefile.am'
2--- data/Makefile.am 2010-03-22 10:07:24 +0000
3+++ data/Makefile.am 2010-03-24 23:55:36 +0000
4@@ -4,6 +4,8 @@
5 u1-preview.js \
6 u1-songs-clickable.js \
7 load_error.html \
8+ outside_domain.html \
9+ trying_sso.html \
10 connecting.html \
11 in_development.html \
12 screen.css \
13
14=== added file 'data/outside_domain.html'
15--- data/outside_domain.html 1970-01-01 00:00:00 +0000
16+++ data/outside_domain.html 2010-03-24 23:55:36 +0000
17@@ -0,0 +1,56 @@
18+<!doctype html>
19+<html>
20+<head>
21+<title>Loading error</title>
22+<link rel="stylesheet" href="reset.css" type="text/css" media="all">
23+<link rel="stylesheet" href="screen.css" type="text/css" media="all">
24+<script>
25+function goback() {
26+ // We should have been passed, to this page, the referrer and the URL they went to in error, separated by :::
27+ if (location.search && location.search.indexOf(":::") != -1) {
28+ var parts = location.search.substr(1).split(":::");
29+ if (parts.length != 2) {
30+ history.go(-1);
31+ }
32+ var from_url = parts[0];
33+ var to_url = parts[1];
34+ var combining = "&";
35+ if (from_url.indexOf("?") == -1) {
36+ combining = "?"
37+ }
38+ var go_back_url = from_url + combining + "went_to_url_in_error=" + escape(to_url);
39+ location.href = go_back_url;
40+ } else {
41+ history.go(-1);
42+ }
43+}
44+</script>
45+</head>
46+<body class="downloads">
47+<div id="header">
48+
49+<div class="wrap">
50+<h1 id="logo">Ubuntu One Music Store</h1>
51+
52+</div><!-- close .wrap -->
53+</div><!-- close #header -->
54+
55+<div class="superfluous">
56+<div id="content">
57+<div class="access">
58+ <h1>Sorry!</h1>
59+<h2>The link you clicked is currently unsupported.
60+Please try exploring a different part of the music store.</h2>
61+
62+<p><button onclick="goback()"><span>Go back</span></button></p>
63+</div>
64+</div>
65+
66+</div>
67+</div>
68+<div id="footer">
69+<div class="wrap">
70+</div>
71+</div>
72+</body>
73+</html>
74
75=== added file 'data/trying_sso.html'
76--- data/trying_sso.html 1970-01-01 00:00:00 +0000
77+++ data/trying_sso.html 2010-03-24 23:55:36 +0000
78@@ -0,0 +1,58 @@
79+<!doctype html>
80+<html>
81+<head>
82+<title>Loading error</title>
83+<link rel="stylesheet" href="reset.css" type="text/css" media="all">
84+<link rel="stylesheet" href="screen.css" type="text/css" media="all">
85+<script>
86+function carry_on() {
87+ // We should have been passed, to this page, the referrer, the URL they
88+ // went to in error, and the store front page, separated by :::
89+ if (location.search && location.search.indexOf(":::") != -1) {
90+ var parts = location.search.substr(1).split(":::");
91+ if (parts.length != 3) {
92+ history.go(-1);
93+ }
94+ var from_url = parts[0];
95+ var to_url = parts[1];
96+ var front_page = parts[2];
97+ var combining = "&";
98+ if (front_page.indexOf("?") == -1) {
99+ combining = "?"
100+ }
101+ var go_back_url = front_page + combining + "went_to_url_in_error=" +
102+ escape(to_url) + "&came_from_url=" + escape(from_url);
103+ location.href = go_back_url;
104+ } else {
105+ history.go(-1);
106+ }
107+}
108+</script>
109+</head>
110+<body class="downloads">
111+<div id="header">
112+
113+<div class="wrap">
114+<h1 id="logo">Ubuntu One Music Store</h1>
115+
116+</div><!-- close .wrap -->
117+</div><!-- close #header -->
118+
119+<div class="superfluous">
120+<div id="content">
121+<div class="access">
122+ <h1>Sorry!</h1>
123+<h2>An error has occurred. Please ensure that your
124+computer is connected to Ubuntu One.</h2>
125+<p><button onclick="carry_on()"><span>Go back</span></button></p>
126+</div>
127+</div>
128+
129+</div>
130+</div>
131+<div id="footer">
132+<div class="wrap">
133+</div>
134+</div>
135+</body>
136+</html>
137
138=== modified file 'libubuntuone/u1-music-store.c'
139--- libubuntuone/u1-music-store.c 2010-03-23 12:19:23 +0000
140+++ libubuntuone/u1-music-store.c 2010-03-24 23:55:36 +0000
141@@ -25,6 +25,7 @@
142 #include <webkit/webkit.h>
143 #include <dbus/dbus-glib.h>
144 #include <libsoup/soup-gnome-features.h>
145+#include <libsoup/soup-uri.h>
146 #include <gnome-keyring.h>
147 #include "oauth.h"
148 #include "u1-music-store.h"
149@@ -39,6 +40,8 @@
150 #define U1_NOT_REGISTERED_URL "https://one.ubuntu.com/music/notregistered?returnUrl="
151
152 #define U1_DEFAULT_ERROR_PAGE "load_error.html"
153+#define U1_OUTSIDE_DOMAIN_ERROR_PAGE "outside_domain.html"
154+#define U1_TRYING_SSO_ERROR_PAGE "trying_sso.html"
155 #define U1_IN_DEVELOPMENT_PAGE "in_development.html"
156 #define U1_CONNECTING_PAGE "connecting.html"
157 #define U1_INITIAL_PAGE "<html><body>Loading Ubuntu One music store</body></html>"
158@@ -241,6 +244,63 @@
159 gchar *not_registered_url;
160 } NotRegisteredReplacementData;
161
162+static gchar *
163+get_url_to_use (U1MusicStore *music_store)
164+{
165+ gchar *oauth_token = NULL, *oauth_token_secret = NULL, *real_url;
166+ const gchar *url_to_use;
167+
168+ /* If U1MUSICSTOREURL is defined, use that instead of the real URL */
169+ if (! (url_to_use = g_getenv ("U1MUSICSTOREURL")))
170+ url_to_use = "https://one.ubuntu.com";
171+
172+ if (music_store->priv->base_url != NULL)
173+ g_free (music_store->priv->base_url);
174+
175+ music_store->priv->base_url = g_strdup (url_to_use);
176+
177+ /* OAUth sign the URL */
178+ if (g_str_has_prefix (url_to_use, "http://localhost") || g_str_has_prefix (url_to_use, "http://127.0.0.1")) {
179+ const gchar *oauthfile;
180+
181+ oauthfile = g_getenv ("OAUTHKEYFILE");
182+ if (oauthfile != NULL) {
183+ gchar *oauthstring;
184+ gsize len;
185+
186+ if (g_file_get_contents (oauthfile, &oauthstring, &len, NULL)) {
187+ parse_oauth_string (oauthstring, &oauth_token, &oauth_token_secret);
188+ g_free (oauthstring);
189+ }
190+ } else {
191+ webkit_web_view_load_string (WEBKIT_WEB_VIEW (music_store->priv->web_viewer),
192+ "Fail! If you specify U1MUSICSTOREURL you must "
193+ "also specify OAUTHKEYFILE as a file with OAuth keys in it",
194+ "text/html", "utf-8", "file:///");
195+ return NULL;
196+ }
197+ } else
198+ get_credentials_from_keyring (&oauth_token, &oauth_token_secret);
199+
200+ if (oauth_token == NULL || oauth_token_secret == NULL)
201+ real_url = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_NOT_LOGGED_IN_STORE_URL);
202+ else {
203+ gchar *s = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_STORE_URL);
204+
205+ real_url = oauth_sign_url2 (s, NULL, OA_HMAC, "GET",
206+ "ubuntuone", "hammertime",
207+ oauth_token, oauth_token_secret);
208+ g_free (s);
209+ }
210+
211+ g_free (oauth_token);
212+ g_free (oauth_token_secret);
213+
214+ return real_url;
215+}
216+
217+
218+
219 static void
220 got_new_dbus_credentials_cb (DBusGProxy *proxy, const gchar *realm, const gchar *consumer_key, gpointer user_data)
221 {
222@@ -329,6 +389,64 @@
223 gpointer user_data)
224 {
225 U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
226+ SoupURI *parsed_uri;
227+
228+ parsed_uri = soup_uri_new (webkit_network_request_get_uri (request));
229+ if (parsed_uri != NULL) {
230+ if (!g_strcmp0 ((const gchar *) parsed_uri->host, "www.7digital.com")) {
231+ /* host is 7digital.com. It must be in our store. */
232+ if (!g_str_has_prefix (parsed_uri->path, "/stores/")) {
233+ /* a 7digital URL not in our store. Die */
234+ gchar *to_and_from_error_uris;
235+ g_debug("Hitting the unbranded store, so throwing an error");
236+ to_and_from_error_uris = g_strdup_printf ("%s:::%s",
237+ webkit_web_view_get_uri (web_view),
238+ webkit_network_request_get_uri (request));
239+ load_internal_html_page (web_view, U1_OUTSIDE_DOMAIN_ERROR_PAGE, to_and_from_error_uris);
240+ g_free (to_and_from_error_uris);
241+ }
242+ }
243+ if (!g_strcmp0 ((const gchar *) parsed_uri->host, "one.ubuntu.com")) {
244+ /* host is one.ubuntu.com. It must not be the login page */
245+ if (g_str_has_prefix (parsed_uri->path, "/auth/")) {
246+ /* trying to log the user into o.u.c inside the webview. Die. */
247+ gchar *real_url;
248+ gchar *to_and_from_error_uris;
249+ real_url = get_url_to_use (music_store);
250+ to_and_from_error_uris = g_strdup_printf ("%s:::%s:::%s",
251+ webkit_web_view_get_uri (web_view),
252+ webkit_network_request_get_uri (request),
253+ real_url);
254+ g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error");
255+ if (real_url != NULL) {
256+ load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
257+ g_free (real_url);
258+ } else {
259+ load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
260+ }
261+ g_free (to_and_from_error_uris);
262+ }
263+ }
264+ if (!g_strcmp0 ((const gchar *) parsed_uri->host, "login.ubuntu.com")) {
265+ /* host is SSO. Die. */
266+ gchar *real_url;
267+ gchar *to_and_from_error_uris;
268+ real_url = get_url_to_use (music_store);
269+ to_and_from_error_uris = g_strdup_printf ("%s:::%s:::%s",
270+ webkit_web_view_get_uri (web_view),
271+ webkit_network_request_get_uri (request),
272+ real_url);
273+ g_debug("Being led through Ubuntu One login inside Rhythmbox, so throwing an error");
274+ if (real_url != NULL) {
275+ load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, to_and_from_error_uris);
276+ g_free (real_url);
277+ } else {
278+ load_internal_html_page (web_view, U1_TRYING_SSO_ERROR_PAGE, NULL);
279+ }
280+ g_free (to_and_from_error_uris);
281+ }
282+
283+ }
284
285 /* Remove watching callback for the page */
286 if (music_store->priv->watch_id != 0) {
287@@ -681,61 +799,6 @@
288 return TRUE;
289 }
290
291-static gchar *
292-get_url_to_use (U1MusicStore *music_store)
293-{
294- gchar *oauth_token = NULL, *oauth_token_secret = NULL, *real_url;
295- const gchar *url_to_use;
296-
297- /* If U1MUSICSTOREURL is defined, use that instead of the real URL */
298- if (! (url_to_use = g_getenv ("U1MUSICSTOREURL")))
299- url_to_use = "https://one.ubuntu.com";
300-
301- if (music_store->priv->base_url != NULL)
302- g_free (music_store->priv->base_url);
303-
304- music_store->priv->base_url = g_strdup (url_to_use);
305-
306- /* OAUth sign the URL */
307- if (g_str_has_prefix (url_to_use, "http://localhost") || g_str_has_prefix (url_to_use, "http://127.0.0.1")) {
308- const gchar *oauthfile;
309-
310- oauthfile = g_getenv ("OAUTHKEYFILE");
311- if (oauthfile != NULL) {
312- gchar *oauthstring;
313- gsize len;
314-
315- if (g_file_get_contents (oauthfile, &oauthstring, &len, NULL)) {
316- parse_oauth_string (oauthstring, &oauth_token, &oauth_token_secret);
317- g_free (oauthstring);
318- }
319- } else {
320- webkit_web_view_load_string (WEBKIT_WEB_VIEW (music_store->priv->web_viewer),
321- "Fail! If you specify U1MUSICSTOREURL you must "
322- "also specify OAUTHKEYFILE as a file with OAuth keys in it",
323- "text/html", "utf-8", "file:///");
324- return NULL;
325- }
326- } else
327- get_credentials_from_keyring (&oauth_token, &oauth_token_secret);
328-
329- if (oauth_token == NULL || oauth_token_secret == NULL)
330- real_url = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_NOT_LOGGED_IN_STORE_URL);
331- else {
332- gchar *s = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_STORE_URL);
333-
334- real_url = oauth_sign_url2 (s, NULL, OA_HMAC, "GET",
335- "ubuntuone", "hammertime",
336- oauth_token, oauth_token_secret);
337- g_free (s);
338- }
339-
340- g_free (oauth_token);
341- g_free (oauth_token_secret);
342-
343- return real_url;
344-}
345-
346 static gboolean
347 load_real_store_cb (gpointer user_data)
348 {

Subscribers

People subscribed via source and target branches