navossoc / KeePass-Yet-Another-Favicon-Downloader

Yet Another Favicon Downloader for KeePass 2.x
MIT License
534 stars 31 forks source link

Downloading with custom provider Google with unexpected behaviour/result from Google API #69

Open Eddict opened 2 years ago

Eddict commented 2 years ago

hi, i have this url; https://www.pluimen.nl which has a (regular) favicon.

var hostname = GetValidHost(url); rips of the https part and only the domain is passed in the next lines of code

providerURL has a final value of https://www.google.com/s2/favicons?domain=www.pluimen.nl&sz=128

that address gets redirected to https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://www.pluimen.nl&size=128 which leads to this default broken/not exiting pic; image

if you check that redirected url, it uses http instead of https 🤨 but the API does that for every url so i do not understand this behavior. perhaps i would if the http:// address, in this case http://www.pluimen.nl, would lead to a 404 or whatever error, but it gets redirected as expected to https://www.pluimen.nl

then i just replaced the http by https https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://www.pluimen.nl&size=128 it leads to image (showing the 16 pixel size here for clarity)

of course you cannot do anything about this, but then i wondered if the API has some sort of parameter which can set/force https. there is none it seems, the whole API is undocumented already anyway.

but then i tried the following (added the protocol to the domain param); https://www.google.com/s2/favicons?domain=https://www.pluimen.nl&sz=128 and that gets redirected to https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://www.pluimen.nl&size=128 so that way the https part gets preserved 🥳

so would it be possible to change this? so prefixing the final value of the domain parameter with the http(s):// protocol part. thanks a lot!

regards Eddict

navossoc commented 2 years ago

I think you can hard code the https prefix, like this:

https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://{URL:HOST}&size={YAFD:ICON_SIZE}

You can use the placeholders that are available right now to build our own URLs. {URL:HOST} and {YAFD:ICON_SIZE}

In the future I can try to parse the custom URL provided and expose more placeholders, like: {URL:SCM} https://keepass.info/help/base/placeholders.html

Cheers

Eddict commented 2 years ago

i guess you mean this? (i dont want to 'hardcode' the redirected url) https://www.google.com/s2/favicons?domain=https://{URL:HOST}&sz={YAFD:ICON_SIZE}

nice alternative indeed, but then i force everything to https, not sure if that will ever lead to issues (although http addresses are ver rare and should be avoided anyway).

i like the placeholders idea, let me play with that! maybe i can code it myself and create a pull request when done. thanks again