Skip to content

[Bug] Infinite loop risk in GitLab contributions fetch when x-next-page header is malformed #1247

@akhilmodi29

Description

@akhilmodi29

Bug Description

The fetchGitLabContributions() function in the contributions API route
has no page limit cap. If GitLab returns a malformed x-next-page header
or the same page number repeatedly (due to a proxy or GitLab bug), the
while loop runs forever — hanging the server request indefinitely.

Steps to Reproduce

  1. Connect a GitLab account
  2. Simulate a malformed x-next-page response header from GitLab
  3. Hit /api/metrics/contributions
  4. Observe: request hangs indefinitely, never resolves

Expected Behavior

The fetch should stop after a reasonable number of pages and return
whatever data was collected so far — exactly like the GitHub fetch
already does with its while (page <= 10) cap.

Root Cause

In fetchGitLabContributions() inside
src/app/api/metrics/contributions/route.ts, the while loop condition
is only while (page > 0) with no upper bound. The GitHub fetch in
the same file correctly uses while (page <= 10) as a safety cap —
the GitLab fetch is missing this protection.

Fix

Add a MAX_PAGES = 10 constant and update the loop condition:

const MAX_PAGES = 10;
while (page > 0 && page <= MAX_PAGES) {

File Affected

src/app/api/metrics/contributions/route.tsfetchGitLabContributions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageNeeds maintainer triage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions