Skip to content

Commit

Permalink
Add-on handler/update check: spoof the user agent when attempting to …
Browse files Browse the repository at this point in the history
…obtain update data from external websites.

NV Access servers do allow Python/urllib whereas others may not. Some hosting services block Python to avoid bots. Therefore spoof the user agent and say that this is latest Microsoft Edge (92 as of Add-on Updater 21.09).
  • Loading branch information
josephsl committed Aug 28, 2021
1 parent c23c904 commit 8983ec3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions addon/globalPlugins/addonUpdater/addonHandlerEx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Proof of concept implementation of NVDA Core issue 3208.

from urllib.request import urlopen
from urllib.request import urlopen, Request
import threading
import wx
import json
Expand Down Expand Up @@ -231,13 +231,22 @@ def fetchAddonInfo(info, results, addon, manifestInfo, addonsData):
# Some add-ons require traversing another URL.
if ".nvda-addon" not in addonUrl:
res = None
# Some hosting services block Python/urllib in hopes of avoding bots.
# Therefore spoof the user agent to say this is latest Microsoft Edge.
# Source: Stack Overflow, Google searches on Apache/mod_security
req = Request(
f"https://addons.nvda-project.org/files/get.php?file={addonKey}",
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.78" # NOQA: E501
}
)
try:
res = urlopen(f"https://addons.nvda-project.org/files/get.php?file={addonKey}")
res = urlopen(req)
except IOError as e:
# SSL issue (seen in NVDA Core earlier than 2014.1).
if isinstance(e.strerror, ssl.SSLError) and e.strerror.reason == "CERTIFICATE_VERIFY_FAILED":
addonUtils._updateWindowsRootCertificates()
res = urlopen(f"https://addons.nvda-project.org/files/get.php?file={addonKey}")
res = urlopen(req)
else:
pass
finally:
Expand Down

0 comments on commit 8983ec3

Please sign in to comment.