Skip to content
Open
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
19 changes: 17 additions & 2 deletions src/routers/admin/oss-sponsorship-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ import { TRPCError } from '@trpc/server';
import { getIntegrationForOrganization } from '@/lib/integrations/db/platform-integrations';
import { getAgentConfig } from '@/lib/agent-config/db/agent-configs';

/**
* Validate that a URL is strictly a GitHub.com URL.
* Rejects lookalike hostnames like github.com.evil.com.
*/
function isStrictGitHubUrl(url: string): boolean {
try {
const parsed = new URL(url);
return parsed.hostname === 'github.com' || parsed.hostname === 'www.github.com';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[WARNING]: isStrictGitHubUrl() allows non-HTTPS GitHub URLs

If this URL is ever used as a clickable link (emails, UI, logs), allowing http: increases exposure to downgrade/MITM. Consider requiring https: in addition to the strict hostname check.

Suggested change
return parsed.hostname === 'github.com' || parsed.hostname === 'www.github.com';
return parsed.protocol === 'https:' && (parsed.hostname === 'github.com' || parsed.hostname === 'www.github.com');

} catch {
return false;
}
}

const OssCsvRowSchema = z.object({
githubUrl: z.string().url(),
githubUrl: z.string().url().refine(isStrictGitHubUrl, {
message: 'URL must be a github.com URL',
}),
email: z.string().email(),
creditsDollars: z.number().nonnegative(),
tier: z.union([z.literal(1), z.literal(2), z.literal(3)]),
Expand All @@ -47,7 +62,7 @@ function escapeIlikePattern(str: string): string {
function extractRepoNameFromUrl(githubUrl: string): string | null {
try {
const parsed = new URL(githubUrl);
if (!parsed.hostname.includes('github.com')) {
if (parsed.hostname !== 'github.com' && parsed.hostname !== 'www.github.com') {
return null;
}
const pathParts = parsed.pathname.split('/').filter(Boolean);
Expand Down