Skip to content

Commit 0a7ebd8

Browse files
waleedlatif1claude
andcommitted
fix(gitlab): pin pagination cursor to configured host before following it
The repository-tree keyset cursor stores GitLab's verbatim rel="next" URL and re-fetches it with an Authorization: Bearer header. Assert the cursor's origin matches the configured apiBase before following it, so a tampered or corrupted fileNextUrl cannot exfiltrate the access token to an attacker-controlled host. Fails closed on mismatch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 85942a5 commit 0a7ebd8

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

apps/sim/connectors/gitlab/gitlab.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ function parseNextLink(linkHeader: string | null): string | undefined {
103103
return undefined
104104
}
105105

106+
/**
107+
* Returns true when `candidate` resolves to the same origin as `base`. Used to
108+
* pin a persisted pagination cursor to the configured GitLab host before
109+
* following it with an `Authorization` header, so a tampered or corrupted
110+
* `fileNextUrl` cannot exfiltrate the access token to an attacker-controlled
111+
* host. Returns false on any unparseable URL.
112+
*/
113+
function isSameOrigin(candidate: string, base: string): boolean {
114+
try {
115+
return new URL(candidate).origin === new URL(base).origin
116+
} catch {
117+
return false
118+
}
119+
}
120+
106121
/**
107122
* Returns the ordered list of active sync phases for a content-type choice.
108123
*/
@@ -741,6 +756,9 @@ export const gitlabConnector: ConnectorConfig = {
741756
per_page: String(PAGE_SIZE),
742757
pagination: 'keyset',
743758
})
759+
if (state.fileNextUrl && !isSameOrigin(state.fileNextUrl, apiBase)) {
760+
throw new Error('GitLab pagination cursor points to an unexpected host')
761+
}
744762
const url =
745763
state.fileNextUrl ??
746764
`${apiBase}/projects/${encodedProject}/repository/tree?${treeParams.toString()}`

0 commit comments

Comments
 (0)