-
-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add validation of update mirror urls #17310
Draft
christopherpross
wants to merge
7
commits into
nvaccess:master
Choose a base branch
from
christopherpross:feature/#17205
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
973f4e3
refactor(updateCheck): extract response parsing logic into separate f…
christopherpross dbf8957
add(updateCheck): add update mirror url validation to the UI (#17205)
christopherpross e5f7fda
Pre-commit auto-fix
pre-commit-ci[bot] b122637
documentation(updateCheck): update changelog to mention the pull requ…
christopherpross 37955b3
Merge branch 'feature/#17205' of https://github.com/christopherpross/…
christopherpross 6e38dd7
Apply suggestions from code review
christopherpross 9b78b40
Update user_docs/en/changes.md
christopherpross File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -999,6 +999,7 @@ def onChangeMirrorURL(self, evt: wx.CommandEvent | wx.KeyEvent): | |||||||||||
configPath=("update", "serverURL"), | ||||||||||||
helpId="SetURLDialog", | ||||||||||||
urlTransformer=lambda url: f"{url}?versionType=stable", | ||||||||||||
responseValidator=_isResponseUpdateMirrorValid, | ||||||||||||
) | ||||||||||||
ret = changeMirror.ShowModal() | ||||||||||||
if ret == wx.ID_OK: | ||||||||||||
|
@@ -5595,3 +5596,18 @@ def _isResponseAddonStoreCacheHash(response: requests.Response) -> bool: | |||||||||||
# While the NV Access Add-on Store cache hash is a git commit hash as a string, other implementations may use a different format. | ||||||||||||
# Therefore, we only check if the data is a non-empty string. | ||||||||||||
return isinstance(data, str) and bool(data) | ||||||||||||
|
||||||||||||
|
||||||||||||
def _isResponseUpdateMirrorValid(response: requests.Response) -> bool: | ||||||||||||
if not response.ok: | ||||||||||||
return False | ||||||||||||
|
||||||||||||
responseContent = response.text | ||||||||||||
Comment on lines
+5602
to
+5605
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
try: | ||||||||||||
parsedResponse = updateCheck.parseUpdateCheckResponse(responseContent) | ||||||||||||
except Exception as e: | ||||||||||||
log.error(f"Error parsing update mirror response: {e}") | ||||||||||||
return False | ||||||||||||
|
||||||||||||
return parsedResponse is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -118,6 +118,27 @@ def getQualifiedDriverClassNameForStats(cls): | |||||||
return "%s (core)" % name | ||||||||
|
||||||||
|
||||||||
def parseUpdateCheckResponse(data: str) -> Optional[Dict[str, str]]: | ||||||||
christopherpross marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
""" | ||||||||
Parses the update response and returns a dictionary with metadata. | ||||||||
|
||||||||
:param data: The raw server response as a UTF-8 decoded string. | ||||||||
:return: A dictionary containing the update metadata, or None if the format is invalid. | ||||||||
""" | ||||||||
if not data.strip(): | ||||||||
return None | ||||||||
|
||||||||
metadata = {} | ||||||||
for line in data.splitlines(): | ||||||||
try: | ||||||||
key, val = line.split(": ", 1) | ||||||||
metadata[key] = val | ||||||||
except ValueError: | ||||||||
return None # Invalid format | ||||||||
|
||||||||
return metadata | ||||||||
|
||||||||
|
||||||||
UPDATE_FETCH_TIMEOUT_S = 30 # seconds | ||||||||
|
||||||||
|
||||||||
|
@@ -187,15 +208,10 @@ def checkForUpdate(auto: bool = False) -> Optional[Dict]: | |||||||
raise | ||||||||
if res.code != 200: | ||||||||
raise RuntimeError("Checking for update failed with code %d" % res.code) | ||||||||
info = {} | ||||||||
for line in res: | ||||||||
# #9819: update description resource returns bytes, so make it Unicode. | ||||||||
line = line.decode("utf-8").rstrip() | ||||||||
try: | ||||||||
key, val = line.split(": ", 1) | ||||||||
except ValueError: | ||||||||
raise RuntimeError("Error in update check output") | ||||||||
info[key] = val | ||||||||
|
||||||||
data = res.text | ||||||||
info = parseUpdateCheckResponse(data) | ||||||||
Comment on lines
+212
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
if not info: | ||||||||
return None | ||||||||
return info | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your PR description, you say:
However it doesn't seem that you have implemented this in
_isResponseUpdateMirrorValid
or anywhere else. Am I missing something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SaschaCowley Hey, sorry I see. While merging, there is a change not applied. So this is lost. In the next few days, I will fix that. Sorry for the inconvinience.