Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/github_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hashlib
import io
import logging
import re
import uuid
from datetime import datetime
from typing import Any
Expand All @@ -23,7 +24,10 @@
from sentry_sdk._types import Event

GITHUB_API_URL = "https://api.github.com"
SENTRY_HOST = "sentry.io"
# sentry.io or a subdomain. Labels can only hold letters, digits, and hyphens: the DSN's
# host can keep a backslash, which requests reads as the start of the path, so the
# envelope for `evil.example\.sentry.io` would go to evil.example
SENTRY_HOST_PATTERN = re.compile(r"(?:[a-z0-9-]+\.)*sentry\.io")


class GithubSentryError(Exception):
Expand Down Expand Up @@ -51,9 +55,7 @@ def __init__(self, token: str | None, dsn: str, dry_run: bool = False) -> None:
parsed = Dsn(dsn)
# Envelopes carry the org's CI data, so only post them to Sentry over HTTPS
host: str = parsed.host
if parsed.scheme != "https" or not (
host == SENTRY_HOST or host.endswith(f".{SENTRY_HOST}")
):
if parsed.scheme != "https" or not SENTRY_HOST_PATTERN.fullmatch(host):
raise BadDsn(f"Not a Sentry DSN host: {parsed.scheme}://{host}")
auth = parsed.to_auth()
self.sentry_key = auth.public_key
Expand Down
3 changes: 3 additions & 0 deletions tests/test_github_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def test_initialize_with_dsn(dsn: str, sentry_project_url: str) -> None:
"https://foo@sentry.io.example.com/1234",
"http://foo@random.ingest.sentry.io/1234",
"http://foo:secret@sentry.example.com:9000/sentry/1234",
# requests would send these to evil.example
"https://foo@evil.example\\.sentry.io/1234",
"https://foo@evil.example\\.sentry.io:8443/1234",
],
)
def test_initialize_with_invalid_dsn(dsn: str) -> None:
Expand Down
Loading