Skip to content

Potential fix for code scanning alert no. 141: Full server-side request forgery#8093

Open
grantfitzsimmons wants to merge 1 commit into
mainfrom
alert-autofix-141
Open

Potential fix for code scanning alert no. 141: Full server-side request forgery#8093
grantfitzsimmons wants to merge 1 commit into
mainfrom
alert-autofix-141

Conversation

@grantfitzsimmons
Copy link
Copy Markdown
Member

Potential fix for https://github.com/specify/specify7/security/code-scanning/141

General fix: enforce a server-side allowlist for any remotely fetched mapping URL, and reject all other remote URLs before calling requests.get. Keep existing local-path behavior unchanged.

Best fix in this code: in specifyweb/backend/trees/default_tree_files.py, add a validation helper that only permits HTTPS URLs to files.specifysoftware.org and only for known mapping paths under /treerows/ that are already handled by local mapping logic (KNOWN_REMOTE_DEFAULT_TREE_PATHS plus the existing /treerows/*.json discipline mapping pattern). Then call this validator in load_default_tree_json right before requests.get(source). If invalid, raise ValueError so existing callers’ except Exception paths return their current 404 error response without broader functional changes.

This single change covers both alert variants because both flows call load_default_tree_json(mapping_url).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…st forgery

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@coderabbitai

This comment was marked as off-topic.

@grantfitzsimmons grantfitzsimmons marked this pull request as ready for review May 19, 2026 04:43
@grantfitzsimmons grantfitzsimmons added this to the 7.12.1 milestone May 19, 2026
@grantfitzsimmons grantfitzsimmons requested a review from Copilot May 19, 2026 04:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses code scanning alert #141 (full SSRF) by restricting which remote URLs can be fetched when loading default tree mapping JSON, introducing a server-side allowlist and rejecting other remote sources before issuing requests.get.

Changes:

  • Added _is_allowed_remote_mapping_url() to allow only https://files.specifysoftware.org and specific mapping-style paths.
  • Enforced the allowlist in load_default_tree_json() by rejecting disallowed sources prior to requests.get.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


def _is_allowed_remote_mapping_url(source: str) -> bool:
parsed = urlparse(source.strip())
if parsed.scheme != 'https' or parsed.netloc != 'files.specifysoftware.org':
Comment on lines +48 to +49
if parsed.path.startswith('/treerows/'):
stem = Path(unquote(parsed.path)).stem.lower()
Comment on lines 132 to 133
response = requests.get(source)
response.raise_for_status()
Comment on lines +129 to +130
if not _is_allowed_remote_mapping_url(source):
raise ValueError('Remote mapping URL is not allowed.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋Back Log

Development

Successfully merging this pull request may close these issues.

2 participants