Skip to content

Commit 6709656

Browse files
waleedlatif1claude
andcommitted
refactor(okta): move validateOktaDomain to centralized input-validation
- Moved validateOktaDomain from tools/okta/types.ts to lib/core/security/input-validation.ts alongside other validation utils - Added .trim() to handle copy-paste whitespace in domain input - Updated all 18 tool files to import from the new location Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c613e78 commit 6709656

20 files changed

+126
-117
lines changed

apps/sim/lib/core/security/input-validation.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,3 +1192,33 @@ export function validateCallbackUrl(url: string): boolean {
11921192
return false
11931193
}
11941194
}
1195+
1196+
const OKTA_DOMAIN_PATTERN =
1197+
/^[a-zA-Z0-9][a-zA-Z0-9-]*\.(okta|okta-gov|okta-emea|oktapreview|trexcloud)\.com$/
1198+
1199+
/**
1200+
* Validates and sanitizes an Okta domain to prevent SSRF.
1201+
* Ensures the domain matches a known Okta domain suffix.
1202+
*
1203+
* @param rawDomain - The raw domain string (may include protocol, trailing slash, or whitespace)
1204+
* @returns The cleaned, validated domain string
1205+
* @throws Error if the domain does not match a known Okta domain suffix
1206+
*
1207+
* @example
1208+
* ```typescript
1209+
* const domain = validateOktaDomain(params.domain)
1210+
* // Returns: "dev-123456.okta.com"
1211+
* ```
1212+
*/
1213+
export function validateOktaDomain(rawDomain: string): string {
1214+
const domain = rawDomain
1215+
.trim()
1216+
.replace(/^https?:\/\//, '')
1217+
.replace(/\/$/, '')
1218+
if (!OKTA_DOMAIN_PATTERN.test(domain)) {
1219+
throw new Error(
1220+
`Invalid Okta domain: "${domain}". Must be a valid Okta domain (e.g., dev-123456.okta.com)`
1221+
)
1222+
}
1223+
return domain
1224+
}

apps/sim/tools/okta/activate_user.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaActivateUserParams,
4-
type OktaActivateUserResponse,
5-
type OktaApiError,
6-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaActivateUserParams,
5+
OktaActivateUserResponse,
6+
OktaApiError,
77
} from '@/tools/okta/types'
88
import type { ToolConfig } from '@/tools/types'
99

apps/sim/tools/okta/add_user_to_group.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaAddUserToGroupParams,
4-
type OktaAddUserToGroupResponse,
5-
type OktaApiError,
6-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaAddUserToGroupParams,
5+
OktaAddUserToGroupResponse,
6+
OktaApiError,
77
} from '@/tools/okta/types'
88
import type { ToolConfig } from '@/tools/types'
99

apps/sim/tools/okta/create_group.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaApiError,
4-
type OktaCreateGroupParams,
5-
type OktaCreateGroupResponse,
6-
type OktaGroup,
7-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaApiError,
5+
OktaCreateGroupParams,
6+
OktaCreateGroupResponse,
7+
OktaGroup,
88
} from '@/tools/okta/types'
99
import type { ToolConfig } from '@/tools/types'
1010

apps/sim/tools/okta/create_user.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaApiError,
4-
type OktaCreateUserParams,
5-
type OktaCreateUserResponse,
6-
type OktaUser,
7-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaApiError,
5+
OktaCreateUserParams,
6+
OktaCreateUserResponse,
7+
OktaUser,
88
} from '@/tools/okta/types'
99
import type { ToolConfig } from '@/tools/types'
1010

apps/sim/tools/okta/deactivate_user.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaApiError,
4-
type OktaDeactivateUserParams,
5-
type OktaDeactivateUserResponse,
6-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaApiError,
5+
OktaDeactivateUserParams,
6+
OktaDeactivateUserResponse,
77
} from '@/tools/okta/types'
88
import type { ToolConfig } from '@/tools/types'
99

apps/sim/tools/okta/delete_group.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaApiError,
4-
type OktaDeleteGroupParams,
5-
type OktaDeleteGroupResponse,
6-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaApiError,
5+
OktaDeleteGroupParams,
6+
OktaDeleteGroupResponse,
77
} from '@/tools/okta/types'
88
import type { ToolConfig } from '@/tools/types'
99

apps/sim/tools/okta/delete_user.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaApiError,
4-
type OktaDeleteUserParams,
5-
type OktaDeleteUserResponse,
6-
validateOktaDomain,
7-
} from '@/tools/okta/types'
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type { OktaApiError, OktaDeleteUserParams, OktaDeleteUserResponse } from '@/tools/okta/types'
84
import type { ToolConfig } from '@/tools/types'
95

106
const logger = createLogger('OktaDeleteUser')

apps/sim/tools/okta/get_group.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaApiError,
4-
type OktaGetGroupParams,
5-
type OktaGetGroupResponse,
6-
type OktaGroup,
7-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaApiError,
5+
OktaGetGroupParams,
6+
OktaGetGroupResponse,
7+
OktaGroup,
88
} from '@/tools/okta/types'
99
import type { ToolConfig } from '@/tools/types'
1010

apps/sim/tools/okta/get_user.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createLogger } from '@sim/logger'
2-
import {
3-
type OktaApiError,
4-
type OktaGetUserParams,
5-
type OktaGetUserResponse,
6-
type OktaUser,
7-
validateOktaDomain,
2+
import { validateOktaDomain } from '@/lib/core/security/input-validation'
3+
import type {
4+
OktaApiError,
5+
OktaGetUserParams,
6+
OktaGetUserResponse,
7+
OktaUser,
88
} from '@/tools/okta/types'
99
import type { ToolConfig } from '@/tools/types'
1010

0 commit comments

Comments
 (0)