Skip to content

A local-first personal finance app

[AI] Fix CORS proxy GitHub API allowlist prefix bypass (#8273)

Matiss Janis Aboltins0e3991ad62c7
diff --git a/packages/sync-server/src/app-cors-proxy.js b/packages/sync-server/src/app-cors-proxy.js
index 916df29944..9a7de0bf5c 100644
--- a/packages/sync-server/src/app-cors-proxy.js
+++ b/packages/sync-server/src/app-cors-proxy.js
@@ -91,7 +91,8 @@ function isUrlAllowed(targetUrl) {
targetUrl === repoUrl ||
targetUrl.startsWith(repoUrl + '/') ||
(hostname === 'api.github.com' &&
- url.pathname.startsWith(`/repos/${repoOwner}/${repoName}`)) ||
+ (url.pathname === `/repos/${repoOwner}/${repoName}` ||
+ url.pathname.startsWith(`/repos/${repoOwner}/${repoName}/`))) ||
(hostname === 'raw.githubusercontent.com' &&
url.pathname.startsWith(`/${repoOwner}/${repoName}/`)) ||
(hostname === 'github.com' &&
diff --git a/packages/sync-server/src/app-cors-proxy.test.js b/packages/sync-server/src/app-cors-proxy.test.js
index 48e0eadae3..5fd4e9fb9b 100644
--- a/packages/sync-server/src/app-cors-proxy.test.js
+++ b/packages/sync-server/src/app-cors-proxy.test.js
@@ -264,6 +264,27 @@ describe('app-cors-proxy', () => {
expect(res.statusCode).toBe(200);
});
+ it('should allow the exact GitHub API repo URL for allowlisted repos', async () => {
+ const res = await request(app)
+ .get('/')
+ .query({ url: 'https://api.github.com/repos/user/repo1' });
+
+ expect(res.statusCode).toBe(200);
+ });
+
+ it('should block prefix-matched GitHub API repos that are not allowlisted', async () => {
+ const res = await request(app).get('/').query({
+ url: 'https://api.github.com/repos/user/repo1-private/contents/.env',
+ });
+
+ expect(res.statusCode).toBe(403);
+ expect(res.body.error).toBe('URL not allowed');
+ expect(console.warn).toHaveBeenCalledWith(
+ 'Blocked request to unauthorized URL:',
+ 'https://api.github.com/repos/user/repo1-private/contents/.env',
+ );
+ });
+
it('should allow raw.githubusercontent.com URLs for allowlisted repos', async () => {
const res = await request(app).get('/').query({
url: 'https://raw.githubusercontent.com/user/repo1/main/file.txt',
diff --git a/upcoming-release-notes/fix-cors-proxy-github-allowlist-prefix-bypass.md b/upcoming-release-notes/fix-cors-proxy-github-allowlist-prefix-bypass.md
new file mode 100644
index 0000000000..3382af0dda
--- /dev/null
+++ b/upcoming-release-notes/fix-cors-proxy-github-allowlist-prefix-bypass.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [MatissJanis]
+---
+
+Fix a CORS proxy security issue that could expose private GitHub repositories.