🛂 Auto ban IP on suspected bot publishing (#1095)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced sign-in error handling with specific messages for different error types. - Implemented IP-based restrictions for authentication and publishing actions. - **Bug Fixes** - Updated the retrieval of user session information to improve reliability. - **Documentation** - Updated usage instructions for `getServerSession` to reflect the new authentication options. - **Refactor** - Replaced direct usage of `authOptions` with a new function `getAuthOptions` to dynamically generate authentication options. - Improved IP address extraction logic to handle various header formats. - **Chores** - Added a new `BannedIp` model to the database schema for managing IP-based restrictions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "BannedIp" (
|
||||
"id" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"ip" TEXT NOT NULL,
|
||||
"responsibleTypebotId" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "BannedIp_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "BannedIp_ip_key" ON "BannedIp"("ip");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Answer_storageUsed_idx" ON "Answer"("storageUsed");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BannedIp" ADD CONSTRAINT "BannedIp_responsibleTypebotId_fkey" FOREIGN KEY ("responsibleTypebotId") REFERENCES "Typebot"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BannedIp" ADD CONSTRAINT "BannedIp_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -54,6 +54,7 @@ model User {
|
||||
CollaboratorsOnTypebots CollaboratorsOnTypebots[]
|
||||
workspaces MemberInWorkspace[]
|
||||
sessions Session[]
|
||||
bannedIps BannedIp[]
|
||||
}
|
||||
|
||||
model ApiToken {
|
||||
@@ -186,6 +187,7 @@ model Typebot {
|
||||
isClosed Boolean @default(false)
|
||||
whatsAppCredentialsId String?
|
||||
riskLevel Int?
|
||||
bannedIps BannedIp[]
|
||||
|
||||
@@index([workspaceId])
|
||||
@@index([isArchived, createdAt(sort: Desc)])
|
||||
@@ -338,6 +340,16 @@ model ThemeTemplate {
|
||||
workspaceId String
|
||||
}
|
||||
|
||||
model BannedIp {
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now())
|
||||
ip String @unique
|
||||
responsibleTypebot Typebot @relation(fields: [responsibleTypebotId], references: [id], onDelete: Restrict)
|
||||
responsibleTypebotId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Restrict)
|
||||
userId String
|
||||
}
|
||||
|
||||
enum WorkspaceRole {
|
||||
ADMIN
|
||||
MEMBER
|
||||
|
||||
Reference in New Issue
Block a user