📜 ⬆️ ⬇️

We shorten arbitrary links with G.CO service.



Google recently launched a service to reduce links - G.CO. The service is designed for internal Google services, at the moment it is supported only by Google Maps. There it is possible to shorten the long address of the card. I immediately had a desire to play around with this thing, but rather to shorten the external URL. How I managed it you can read in this article.


')

Catch request


The first thing that occurred to me was to catch the HTTP request to the server and replace the value of the long address. For this, I used the HTTP sniffer. Google sends such a POST request to shorten the link:
http://maps.google.ru/maps/urlshortener?q=http:%2F%2Fmaps.google.ru%2F%3Fll%3D55.354135,40.297852%26spn%3D28.518959,86.572266%26z%3D4%26vpsrc%3D0&abauth={ }&authuser=0 

And from the server comes a similar answer:
 {short_url:"http://g.co/maps/a9qd", status_code:0} 

Unfortunately, if you change the value of q to an arbitrary, Google will not shorten the link, but will return the link we sent to it, for example:
 {short_url:"http://habr.ru/", status_code:0} 

Will not work. Let's think further ...

We are looking for a redirect


The second idea is to find a redirect from maps.google.com to an external site and try to reduce such a link. Unfortunately, the only redirect I found was maps.google.ru/url?q=http://yandex.ru maps.google.ru/url?q=http://yandex.ru , obviously, the redirect with the warning does not suit us, so we will look for another solution. By the way, if the redirect address is * .google.com / * , then the redirect works without any warning. Well, take note of this;)

Google sites


Another thought is to try to push the redirect code into the site created through this service . So, it’s clear that Google’s arbitrary javascript won't be inserted there, so in the page editing panel you need to select “Add additional gadgets” and find redirect in the gadgets selection window, select the URL to which the gadget will redirect and set the delay to 0 in the settings.

And then I thought, because the gadget is inside the iframe, it means that it works like this:
 top.location.href = "http://someurl.com/"; 


Yes, which means that he will redirect the parent window!

Now we need to find the iframe with a dynamic URL on the Google Maps service.

Looking for an iframe on Google Maps


As I expected, it did not take long to search. Iframe was found here:

Here is his address.
Obviously, here you just need to change the url parameter, but here’s the problem again - the url that opens inside the iframe can only be on the maps.google.com domain. And here we use our redirect! We’ll get this address:
 http://maps.google.ru/maps/empw?url=http://maps.google.com/url?q=https://sites.google.com/site/{yoursite} 


In a nutshell, what is happening here:
If maps is opened at maps.google.com/maps/empw , which has src filtered (allowed only for the domain maps.google.com), we go around this filter via the redirect of maps.google.com/url. And maps.google.com/url redirects the address of the iPhone to our Google site. The site Google, in turn, is a gadget redirect the parent browser window.

We try to shorten this address, we send a request.
 http://maps.google.ru/maps/urlshortener?q=http://maps.google.ru/maps/empw?url=http://maps.google.com/url?q=https://sites.google.com/site/{yoursite}&abauth={ }&authuser=0 

Everything is working! Fine.

Living example.

Source: https://habr.com/ru/post/127471/


All Articles