Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(security): SSRF, access control, and info disclosure#3815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
952239d
fix(security): scope copilot feedback GET endpoint to authenticated user
waleedlatif1 89b4699
fix(smtp): add SSRF validation and genericize network error messages
waleedlatif1 7b5a296
fix(security): add SSRF validation to SFTP/SSH and access control to …
waleedlatif1 6026598
fix(smtp): restore SMTP response code handling for post-connection er…
waleedlatif1 a3f48e9
fix(security): use session email directly instead of extra DB query
waleedlatif1 c52698d
lint
waleedlatif1 0fa3c3e
fix(auth): revert lint autofix that broke hasExternalApiCredentials r…
waleedlatif1 4c0aa7a
fix(smtp): pin resolved IP to prevent DNS rebinding (TOCTOU)
waleedlatif1 d747565
refactor(security): extract createPinnedLookup helper for DNS rebindi…
waleedlatif1 c9f2a06
fix(security): pin IMAP connections to validated resolved IP
waleedlatif1 d2937d9
lint
waleedlatif1 98e42d3
fix(auth): revert lint autofix on hasExternalApiCredentials return type
waleedlatif1 1db2ab4
fix(security): short-circuit admin check when caller is invitee
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15 apps/sim/app/api/organizations/[id]/invitations/[invitationId]/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server' | ||
| import nodemailer from 'nodemailer' | ||
| import { z } from 'zod' | ||
| import { checkInternalAuth } from '@/lib/auth/hybrid' | ||
| import { validateDatabaseHost } from '@/lib/core/security/input-validation.server' | ||
| import { generateRequestId } from '@/lib/core/utils/request' | ||
| import { RawFileInputArraySchema } from '@/lib/uploads/utils/file-schemas' | ||
| import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' | ||
| @@ -56,6 +57,15 @@ export async function POST(request: NextRequest) { | ||
| const body = await request.json() | ||
| const validatedData = SmtpSendSchema.parse(body) | ||
| const hostValidation = await validateDatabaseHost(validatedData.smtpHost, 'smtpHost') | ||
| if (!hostValidation.isValid) { | ||
| logger.warn(`[${requestId}] SMTP host validation failed`, { | ||
| host: validatedData.smtpHost, | ||
| error: hostValidation.error, | ||
| }) | ||
| return NextResponse.json({ success: false, error: hostValidation.error }, { status: 400 }) | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| logger.info(`[${requestId}] Sending email via SMTP`, { | ||
| host: validatedData.smtpHost, | ||
| port: validatedData.smtpPort, | ||
| @@ -64,8 +74,13 @@ export async function POST(request: NextRequest) { | ||
| secure: validatedData.smtpSecure, | ||
| }) | ||
| // Pin the pre-resolved IP to prevent DNS rebinding (TOCTOU) attacks. | ||
| // Pass resolvedIP as the host so nodemailer connects to the validated address, | ||
| // and set servername for correct TLS SNI/certificate validation. | ||
| const pinnedHost = hostValidation.resolvedIP ?? validatedData.smtpHost | ||
| const transporter = nodemailer.createTransport({ | ||
| host: validatedData.smtpHost, | ||
| host: pinnedHost, | ||
| port: validatedData.smtpPort, | ||
| secure: validatedData.smtpSecure === 'SSL', | ||
| auth: { | ||
| @@ -74,12 +89,8 @@ export async function POST(request: NextRequest) { | ||
| }, | ||
| tls: | ||
| validatedData.smtpSecure === 'None' | ||
| ? { | ||
| rejectUnauthorized: false, | ||
| } | ||
| : { | ||
| rejectUnauthorized: true, | ||
| }, | ||
| ? { rejectUnauthorized: false, servername: validatedData.smtpHost } | ||
| : { rejectUnauthorized: true, servername: validatedData.smtpHost }, | ||
| }) | ||
| const contentType = validatedData.contentType || 'text' | ||
| @@ -189,16 +200,16 @@ export async function POST(request: NextRequest) { | ||
| if (isNodeError(error)) { | ||
| if (error.code === 'EAUTH') { | ||
| errorMessage = 'SMTP authentication failed - check username and password' | ||
| } else if (error.code === 'ECONNECTION' || error.code === 'ECONNREFUSED') { | ||
| } else if ( | ||
| error.code === 'ECONNECTION' || | ||
| error.code === 'ECONNREFUSED' || | ||
| error.code === 'ECONNRESET' || | ||
| error.code === 'ETIMEDOUT' | ||
| ) { | ||
| errorMessage = 'Could not connect to SMTP server - check host and port' | ||
| } else if (error.code === 'ECONNRESET') { | ||
| errorMessage = 'Connection was reset by SMTP server' | ||
| } else if (error.code === 'ETIMEDOUT') { | ||
| errorMessage = 'SMTP server connection timeout' | ||
| } | ||
| } | ||
| // Check for SMTP response codes | ||
| const hasResponseCode = (err: unknown): err is { responseCode: number } => { | ||
| return typeof err === 'object' && err !== null && 'responseCode' in err | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.