GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(github): treat collaborator 404 as unauthorized for ignore · SocketDev/socket-python-cli@3a9cc7a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • socketsecurity/core/scm
    • github.py
  • tests/unit
    • test_ignore_authorization.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎socketsecurity/core/scm/github.py‎

Copy file name to clipboardExpand all lines: socketsecurity/core/scm/github.py
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dataclasses import dataclass
55

66
from git import Optional
7+
from socketdev.exceptions import APIFailure
78

89
from socketsecurity import USER_AGENT
910
from socketsecurity.core import log
@@ -273,6 +274,18 @@ def is_ignore_authorized(self, comment: Comment) -> bool:
273274
permission = (
274275
result["permission"].casefold() in self.WRITE_PERMISSIONS
275276
)
277+
except APIFailure as error:
278+
# GitHub returns 404 when the user is not a collaborator (or
279+
# the caller cannot see the repo). Comments were already listed
280+
# with this token, so 404 is the outsider case, not missing
281+
# scope, and must not fail open under enforce.
282+
if error.status_code == 404:
283+
permission = False
284+
else:
285+
log.warning(
286+
f"Could not read GitHub repository permission for {author}: {error}"
287+
)
288+
permission = None
276289
except Exception as error:
277290
log.warning(
278291
f"Could not read GitHub repository permission for {author}: {error}"
Collapse file

‎tests/unit/test_ignore_authorization.py‎

Copy file name to clipboardExpand all lines: tests/unit/test_ignore_authorization.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from types import SimpleNamespace
99

1010
import pytest
11+
from socketdev.exceptions import APIFailure
1112

1213
from socketsecurity.core.classes import Comment
1314
from socketsecurity.core.scm.github import Github
@@ -81,6 +82,17 @@ def test_github_unreadable_permission_honors_the_command_with_a_warning(caplog):
8182
assert "without verifying write access" in caplog.text
8283

8384

85+
def test_github_404_means_the_commenter_is_not_a_collaborator():
86+
"""GitHub returns 404 when the user is not a collaborator. That is the
87+
drive-by case this gate exists to block, not an undetermined lookup."""
88+
github = _github(
89+
raises=APIFailure("Request failed: 404 Client Error", status_code=404)
90+
)
91+
comment = _comment(user={"login": "outsider"}, author_association="NONE")
92+
93+
assert github.is_ignore_authorized(comment) is False
94+
95+
8496
def test_github_strict_rejects_when_permission_cannot_be_read(caplog):
8597
github = _github(raises=Exception("403 Forbidden"), policy="strict")
8698

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.