Skip to content

Conversation

@sl0thentr0py
Copy link
Member

DESCRIBE YOUR PR

This PR adds comprehensive developer documentation for implementing GitHub link unfurling to develop-docs/integrations/github.mdx. This documentation guides developers on how to enable rich previews for Sentry links shared within GitHub, covering detection, data fetching, formatting options (comments or checks), and best practices. It also updates the integration table in docs/organization/integrations/index.mdx to reflect this new capability for GitHub and GitHub Enterprise.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.

  • Urgent deadline (GA date, etc.):
  • Other deadline:
  • None: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it.
    Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

LEGAL BOILERPLATE

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

EXTRA RESOURCES


Open in Cursor Open in Web

@vercel
Copy link

vercel bot commented Nov 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
develop-docs Error Error Nov 19, 2025 11:30am
sentry-docs Error Error Nov 19, 2025 11:30am

Comment on lines +21 to +23
const fileMatch = url.match(
/https?:\/\/github\.com\/([\w-]+\/[\w-]+)\/blob\/([\w.-]+)\/(.*?)(?:#L(\d+)(?:-L(\d+))?)?$/
);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
a user-provided value
may run slow on strings starting with 'http://github.com/-/-/blob/-/' and with many repetitions of 'http://github.com/-/-/blob/-/a'.
Comment on lines +45 to +48
const response = await fetch(apiUrl, {
headers,
next: {revalidate: 3600}, // Cache for 1 hour
});

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

The
URL
of this request depends on a
user-provided value
.

Copilot Autofix

AI 2 days ago

To properly fix the issue, you should further validate the parsed components (repo, ref, and filePath) extracted from the user-supplied GitHub URL.

  • General approach: After extracting the repo, ref, and filePath via regex, check that they contain only safe, expected characters (e.g., repo and ref are alphanumeric with allowed dashes/underscores/dots, filePath does NOT contain any suspicious segments like .., backslashes, or repeated/leading slashes).
  • Enforce that:
    • Repo matches the GitHub repository "owner/repo" pattern (letters, digits, dashes, underscores, no slashes in owner and repo except separator, etc.).
    • Ref matches common branch, tag, or SHA formats (letters, digits, dashes, dots, underscores).
    • Filepath is a relative path and does not involve path traversal or absolute paths.
  • Ideally, centralize this validation immediately after the regex match, and error out with a clear message if validation fails.
  • No change in external logic or API is needed—only server-side validation of intermediates.
  • Implement the new validation in place after line 29 (extraction), before constructing and using the parsed variables. You may want a helper function to do this.
  • Only referenced standard library/Node.js/TypeScript features are used; no third-party libraries.

Suggested changeset 1
app/api/github-preview/route.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/api/github-preview/route.ts b/app/api/github-preview/route.ts
--- a/app/api/github-preview/route.ts
+++ b/app/api/github-preview/route.ts
@@ -28,6 +28,18 @@
 
   const [, repo, ref, filePath, startLine, endLine] = fileMatch;
 
+  // Strict validation to minimize SSRF and confusions
+  if (
+    !isValidRepo(repo) ||
+    !isValidRef(ref) ||
+    !isValidFilePath(filePath)
+  ) {
+    return NextResponse.json(
+      {error: 'Invalid repository, ref, or file path in GitHub URL'},
+      {status: 400}
+    );
+  }
+
   try {
     // Use GitHub API to fetch file content
     const apiUrl = `https://api.github.com/repos/${repo}/contents/${filePath}?ref=${ref}`;
@@ -131,3 +143,34 @@
 
   return languageMap[ext || ''] || 'text';
 }
+
+// Validate that repo is of the form "owner/repo" with safe characters
+function isValidRepo(repo: string): boolean {
+  // Owner and repo: letters, numbers, -, _, . only (no / except separator)
+  const repoPattern = /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/;
+  return repoPattern.test(repo);
+}
+
+// Validate that ref is a safe branch/tag/SHA representation
+function isValidRef(ref: string): boolean {
+  // Popular refs: allow letters, numbers, -, _, .; SHA is hex
+  const refPattern = /^[a-zA-Z0-9_.\-\/]+$/;
+  // Disallow empty
+  return refPattern.test(ref) && ref.length > 0;
+}
+
+// Validate file path is relative, no path traversal or backslash, no leading /
+function isValidFilePath(filePath: string): boolean {
+  // Disallow path traversal, windows style backslash, or absolute paths
+  if (
+    filePath.includes('..') ||
+    filePath.startsWith('/') ||
+    filePath.startsWith('\\') ||
+    filePath.includes('\\')
+  ) {
+    return false;
+  }
+  // Allow alphanum, dashes, underscores, dots, slashes, and common folders
+  const filePathPattern = /^[\w\-./]+$/;
+  return filePathPattern.test(filePath);
+}
EOF
@@ -28,6 +28,18 @@

const [, repo, ref, filePath, startLine, endLine] = fileMatch;

// Strict validation to minimize SSRF and confusions
if (
!isValidRepo(repo) ||
!isValidRef(ref) ||
!isValidFilePath(filePath)
) {
return NextResponse.json(
{error: 'Invalid repository, ref, or file path in GitHub URL'},
{status: 400}
);
}

try {
// Use GitHub API to fetch file content
const apiUrl = `https://api.github.com/repos/${repo}/contents/${filePath}?ref=${ref}`;
@@ -131,3 +143,34 @@

return languageMap[ext || ''] || 'text';
}

// Validate that repo is of the form "owner/repo" with safe characters
function isValidRepo(repo: string): boolean {
// Owner and repo: letters, numbers, -, _, . only (no / except separator)
const repoPattern = /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/;
return repoPattern.test(repo);
}

// Validate that ref is a safe branch/tag/SHA representation
function isValidRef(ref: string): boolean {
// Popular refs: allow letters, numbers, -, _, .; SHA is hex
const refPattern = /^[a-zA-Z0-9_.\-\/]+$/;
// Disallow empty
return refPattern.test(ref) && ref.length > 0;
}

// Validate file path is relative, no path traversal or backslash, no leading /
function isValidFilePath(filePath: string): boolean {
// Disallow path traversal, windows style backslash, or absolute paths
if (
filePath.includes('..') ||
filePath.startsWith('/') ||
filePath.startsWith('\\') ||
filePath.includes('\\')
) {
return false;
}
// Allow alphanum, dashes, underscores, dots, slashes, and common folders
const filePathPattern = /^[\w\-./]+$/;
return filePathPattern.test(filePath);
}
Copilot is powered by AI and may make mistakes. Always verify output.
@codecov
Copy link

codecov bot commented Nov 19, 2025

Bundle Report

Changes will decrease total bundle size by 447.25kB (-3.4%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-server-cjs 12.72MB -40.86kB (-0.32%) ⬇️
sentry-docs-edge-server-array-push (removed) -406.39kB (-100.0%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: sentry-docs-server-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
1729.js -3 bytes 1.74MB -0.0%
../instrumentation.js -3 bytes 1.07MB -0.0%
9523.js -3 bytes 1.04MB -0.0%
../app/[[...path]]/page.js.nft.json -20.39kB 793.63kB -2.5%
../app/platform-redirect/page.js.nft.json -20.39kB 793.54kB -2.51%
../app/sitemap.xml/route.js.nft.json -20.34kB 790.82kB -2.51%
../app/[[...path]]/page.js 3.88kB 623.98kB 0.63%
8164.js (New) 26.79kB 26.79kB 100.0% 🚀
../../types/app/api/github-preview/route.ts (New) 8.73kB 8.73kB 100.0% 🚀
../app/sitemap.xml/route.js -26.32kB 7.96kB -76.77%
../app/api/github-preview/route.js (New) 6.57kB 6.57kB 100.0% 🚀
../app/api/github-preview/route.js.nft.json (New) 615 bytes 615 bytes 100.0% 🚀

Files in ../app/[[...path]]/page.js:

  • ./src/components/githubLinkPreview.tsx → Total Size: 489 bytes

  • ./src/components/githubLinkPreview.module.scss → Total Size: 558 bytes

  • ./src/mdxComponents.ts → Total Size: 4.43kB

  • ./src/components/githubLinkPreview.tsx → Total Size: 7.01kB

App Routes Affected:

App Route Size Change Total Size Change (%)
/ -26.32kB 2.78MB -0.94%
/[[...path]] 3.88kB 3.37MB 0.12%

@codecov
Copy link

codecov bot commented Nov 19, 2025

Bundle Report

Changes will increase total bundle size by 237.94kB (1.02%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-server-cjs 12.72MB -40.86kB (-0.32%) ⬇️
sentry-docs-client-array-push 10.45MB 278.81kB (2.74%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: sentry-docs-client-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
static/chunks/pages/_app-*.js -3 bytes 882.71kB -0.0%
static/css/*.css -1.32kB 4.84kB -21.37%
static/css/*.css 1.21kB 13.91kB 9.5% ⚠️
static/css/*.css -4.23kB 12.57kB -25.18%
static/css/*.css -5.5kB 17.21kB -24.22%
static/css/*.css -928 bytes 961 bytes -49.13%
static/css/*.css -1 bytes 1.89kB -0.05%
static/css/*.css -735.61kB 12.71kB -98.3%
static/css/*.css (New) 748.31kB 748.31kB 100.0% 🚀
static/chunks/8321-*.js -3 bytes 425.87kB -0.0%
server/app/api/github-*.js (New) 268.55kB 268.55kB 100.0% 🚀
server/app/api/ip-*.js 705 bytes 268.54kB 0.26%
server/app/_not-*.js 705 bytes 268.53kB 0.26%
server/app/[[...path]]/page_client-*.js 705 bytes 268.49kB 0.26%
server/app/platform-*.js 764 bytes 253.13kB 0.3%
static/chunks/app/[[...path]]/page-*.js 3.98kB 100.09kB 4.14%
static/chunks/app/platform-*.js 5 bytes 13.38kB 0.04%
static/chunks/webpack-*.js 10 bytes 5.44kB 0.18%
app-*.json 502 bytes 5.1kB 10.92% ⚠️
static/chunks/app/_not-*.js 5 bytes 894 bytes 0.56%
static/chunks/app/api/ip-*.js 5 bytes 894 bytes 0.56%
static/chunks/app/api/github-*.js (New) 894 bytes 894 bytes 100.0% 🚀
static/XfEUAxMX3nwRM7qleacAK/_buildManifest.js (New) 725 bytes 725 bytes 100.0% 🚀
static/XfEUAxMX3nwRM7qleacAK/_ssgManifest.js (New) 77 bytes 77 bytes 100.0% 🚀
static/CNmRYvbtdKLLLD5uT7hJg/_buildManifest.js (Deleted) -684 bytes 0 bytes -100.0% 🗑️
static/CNmRYvbtdKLLLD5uT7hJg/_ssgManifest.js (Deleted) -77 bytes 0 bytes -100.0% 🗑️

Files in static/chunks/app/[[...path]]/page-*.js:

  • ./src/components/githubLinkPreview.module.scss → Total Size: 552 bytes

  • ./src/components/githubLinkPreview.tsx → Total Size: 7.02kB

view changes for bundle: sentry-docs-server-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
1729.js -3 bytes 1.74MB -0.0%
../instrumentation.js -3 bytes 1.07MB -0.0%
9523.js -3 bytes 1.04MB -0.0%
../app/[[...path]]/page.js.nft.json -20.39kB 793.63kB -2.5%
../app/platform-redirect/page.js.nft.json -20.39kB 793.54kB -2.51%
../app/sitemap.xml/route.js.nft.json -20.34kB 790.82kB -2.51%
../app/[[...path]]/page.js 3.88kB 623.98kB 0.63%
8164.js (New) 26.79kB 26.79kB 100.0% 🚀
../../types/app/api/github-preview/route.ts (New) 8.73kB 8.73kB 100.0% 🚀
../app/sitemap.xml/route.js -26.32kB 7.96kB -76.77%
../app/api/github-preview/route.js (New) 6.57kB 6.57kB 100.0% 🚀
../app/api/github-preview/route.js.nft.json (New) 615 bytes 615 bytes 100.0% 🚀

Files in ../app/[[...path]]/page.js:

  • ./src/components/githubLinkPreview.module.scss → Total Size: 558 bytes

  • ./src/mdxComponents.ts → Total Size: 4.43kB

  • ./src/components/githubLinkPreview.tsx → Total Size: 7.01kB

  • ./src/components/githubLinkPreview.tsx → Total Size: 489 bytes

App Routes Affected:

App Route Size Change Total Size Change (%)
/[[...path]] 3.88kB 3.37MB 0.12%
/ -26.32kB 2.78MB -0.94%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants