Skip to content

Commit 98e42d3

Browse files
committed
fix(auth): revert lint autofix on hasExternalApiCredentials return type
Also pin SFTP/SSH connections to validated resolved IP to prevent DNS rebinding.
1 parent d2937d9 commit 98e42d3

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

apps/sim/app/api/tools/sftp/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ export async function createSftpConnection(config: SftpConnectionConfig): Promis
104104
throw new Error(hostValidation.error)
105105
}
106106

107+
const resolvedHost = hostValidation.resolvedIP ?? host.trim()
108+
107109
return new Promise((resolve, reject) => {
108110
const client = new Client()
109111
const port = config.port || 22
@@ -117,7 +119,7 @@ export async function createSftpConnection(config: SftpConnectionConfig): Promis
117119
}
118120

119121
const connectConfig: ConnectConfig = {
120-
host: host.trim(),
122+
host: resolvedHost,
121123
port,
122124
username: config.username,
123125
}

apps/sim/app/api/tools/ssh/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export async function createSSHConnection(config: SSHConnectionConfig): Promise<
121121
throw new Error(hostValidation.error)
122122
}
123123

124+
const resolvedHost = hostValidation.resolvedIP ?? host.trim()
125+
124126
return new Promise((resolve, reject) => {
125127
const client = new Client()
126128
const port = config.port || 22
@@ -134,7 +136,7 @@ export async function createSSHConnection(config: SSHConnectionConfig): Promise<
134136
}
135137

136138
const connectConfig: ConnectConfig = {
137-
host: host.trim(),
139+
host: resolvedHost,
138140
port,
139141
username: config.username,
140142
}

apps/sim/lib/auth/hybrid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const BEARER_PREFIX = 'Bearer '
2525
export function hasExternalApiCredentials(headers: Headers): boolean {
2626
if (headers.has(API_KEY_HEADER)) return true
2727
const auth = headers.get('authorization')
28-
return auth?.startsWith(BEARER_PREFIX)
28+
return auth !== null && auth.startsWith(BEARER_PREFIX)
2929
}
3030

3131
export interface AuthResult {

0 commit comments

Comments
 (0)