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
1 change: 1 addition & 0 deletions surfsense_backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NEXT_FRONTEND_URL=http://localhost:3000

# Auth
AUTH_TYPE=GOOGLE or LOCAL
REGISTRATION_ENABLED= TRUE or FALSE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix formatting for consistency.

The line has a space after the equals sign, which is inconsistent with other environment variable declarations in this file. Additionally, consider quoting the value for better consistency with shell conventions.

Apply this diff to fix the formatting:

-REGISTRATION_ENABLED= TRUE or FALSE
+REGISTRATION_ENABLED="TRUE or FALSE"

Or more clearly document both options:

-REGISTRATION_ENABLED= TRUE or FALSE
+REGISTRATION_ENABLED="TRUE"  # Set to "FALSE" to disable registration
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
REGISTRATION_ENABLED= TRUE or FALSE
REGISTRATION_ENABLED="TRUE or FALSE"
Suggested change
REGISTRATION_ENABLED= TRUE or FALSE
REGISTRATION_ENABLED="TRUE" # Set to "FALSE" to disable registration
🧰 Tools
🪛 dotenv-linter (3.3.0)

[warning] 12-12: [SpaceCharacter] The line has spaces around equal sign

(SpaceCharacter)


[warning] 12-12: [ValueWithoutQuotes] This value needs to be surrounded in quotes

(ValueWithoutQuotes)

🤖 Prompt for AI Agents
In surfsense_backend/.env.example around line 12, the environment variable
declaration contains a space after the equals sign and ambiguous wording; remove
the space so the assignment follows the same no-space convention as other lines,
replace the "or" phrasing with a single recommended example value (TRUE or
FALSE) and optionally show the alternate in a separate commented example or
explicitly state both possible values, and consider recommending quoting (e.g.,
"TRUE" or "FALSE") for consistency with shell conventions.

# For Google Auth Only
GOOGLE_OAUTH_CLIENT_ID=924507538m
GOOGLE_OAUTH_CLIENT_SECRET=GOCSV
Expand Down
14 changes: 13 additions & 1 deletion surfsense_backend/app/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from contextlib import asynccontextmanager

from fastapi import Depends, FastAPI
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy.ext.asyncio import AsyncSession

Expand All @@ -18,6 +18,14 @@ async def lifespan(app: FastAPI):
yield


def registration_allowed():
if not config.REGISTRATION_ENABLED:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail="Registration is disabled"
)
return True


app = FastAPI(lifespan=lifespan)

# Add CORS middleware
Expand All @@ -36,6 +44,7 @@ async def lifespan(app: FastAPI):
fastapi_users.get_register_router(UserRead, UserCreate),
prefix="/auth",
tags=["auth"],
dependencies=[Depends(registration_allowed)], # blocks registration when disabled
)
app.include_router(
fastapi_users.get_reset_password_router(),
Expand All @@ -62,6 +71,9 @@ async def lifespan(app: FastAPI):
),
prefix="/auth/google",
tags=["auth"],
dependencies=[
Depends(registration_allowed)
], # blocks OAuth registration when disabled
)

app.include_router(crud_router, prefix="/api/v1", tags=["crud"])
Expand Down
1 change: 1 addition & 0 deletions surfsense_backend/app/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Config:

# Auth
AUTH_TYPE = os.getenv("AUTH_TYPE")
REGISTRATION_ENABLED = os.getenv("REGISTRATION_ENABLED", "TRUE").upper() == "TRUE"

# Google OAuth
GOOGLE_OAUTH_CLIENT_ID = os.getenv("GOOGLE_OAUTH_CLIENT_ID")
Expand Down
14 changes: 14 additions & 0 deletions surfsense_web/app/(home)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ export default function RegisterPage() {

const data = await response.json();

if (!response.ok && response.status === 403) {
const friendlyMessage =
"Registrations are currently closed. If you need access, contact your administrator.";
setErrorTitle("Registration is disabled");
setError(friendlyMessage);
toast.error("Registration is disabled", {
id: loadingToast,
description: friendlyMessage,
duration: 6000,
});
setIsLoading(false);
return;
}

if (!response.ok) {
throw new Error(data.detail || `HTTP ${response.status}`);
}
Expand Down