Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions apps/sim/connectors/gitlab/gitlab.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createLogger } from '@sim/logger'
import { getErrorMessage, toError } from '@sim/utils/errors'
import { GitLabIcon } from '@/components/icons'
import { isSameOrigin } from '@/lib/core/utils/validation'
import { fetchWithRetry, VALIDATE_RETRY_OPTIONS } from '@/lib/knowledge/documents/utils'
import type { ConnectorConfig, ExternalDocument, ExternalDocumentList } from '@/connectors/types'
import { computeContentHash, joinTagArray, parseTagDate } from '@/connectors/utils'
Expand Down Expand Up @@ -741,6 +742,9 @@ export const gitlabConnector: ConnectorConfig = {
per_page: String(PAGE_SIZE),
pagination: 'keyset',
})
if (state.fileNextUrl && !isSameOrigin(state.fileNextUrl, apiBase)) {
throw new Error('GitLab pagination cursor points to an unexpected host')
}
const url =
state.fileNextUrl ??
`${apiBase}/projects/${encodedProject}/repository/tree?${treeParams.toString()}`
Expand Down
13 changes: 7 additions & 6 deletions apps/sim/lib/core/utils/validation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { getBaseUrl } from './urls'

/**
* Checks if a URL is same-origin with the application's base URL.
* Used to prevent open redirect vulnerabilities.
* Checks if a URL is same-origin with a base URL. Defaults to the application's
* base URL, used to prevent open redirect vulnerabilities; pass an explicit
* `base` to pin a URL to another trusted origin (e.g. a configured API host)
* before following it with credentials.
*
* @param url - The URL to validate
* @param base - The origin to compare against (defaults to the app base URL)
* @returns True if the URL is same-origin, false otherwise (secure default)
*/
export function isSameOrigin(url: string): boolean {
export function isSameOrigin(url: string, base: string = getBaseUrl()): boolean {
try {
const targetUrl = new URL(url)
const appUrl = new URL(getBaseUrl())
return targetUrl.origin === appUrl.origin
return new URL(url).origin === new URL(base).origin
} catch {
return false
}
Expand Down
13 changes: 2 additions & 11 deletions apps/sim/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@/lib/core/utils/stream-limits'
import { getBaseUrl, getInternalApiBaseUrl } from '@/lib/core/utils/urls'
import { isUserFile } from '@/lib/core/utils/user-file'
import { isSameOrigin } from '@/lib/core/utils/validation'
import { SIM_VIA_HEADER, serializeCallChain } from '@/lib/execution/call-chain'
import { parseMcpToolId } from '@/lib/mcp/utils'
import { resolveWorkspaceFileReference } from '@/lib/uploads/contexts/workspace/workspace-file-manager'
Expand Down Expand Up @@ -1364,17 +1365,7 @@ function isErrorResponse(
* the platform's own workflow execution endpoints via absolute URL.
*/
function isSelfOriginUrl(url: string): boolean {
try {
const targetOrigin = new URL(url).origin
const publicOrigin = new URL(getBaseUrl()).origin
if (targetOrigin === publicOrigin) return true

const internalOrigin = new URL(getInternalApiBaseUrl()).origin
if (targetOrigin === internalOrigin) return true
} catch {
return false
}
return false
return isSameOrigin(url, getBaseUrl()) || isSameOrigin(url, getInternalApiBaseUrl())
}

/**
Expand Down
Loading