Skip to content
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

Security Enhancement #956

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 11 additions & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ import { createClient } from "redis";
import { logger } from "./logger";
import { type DeployJob, deployJobSchema } from "./schema";
import { deploy } from "./utils";
import rateLimit from "express-rate-limit";

const app = new Hono();
const redisClient = createClient({
url: process.env.REDIS_URL,
});

const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
message: "Too many requests from this IP, please try again later.",
});

app.use(limiter);

app.use(async (c, next) => {
if (c.req.path === "/health") {
return next();
Expand Down Expand Up @@ -57,5 +66,6 @@ const queue = new Queue({
})();

const port = Number.parseInt(process.env.PORT || "3000");
const host = process.env.EXPOSE_ALL_INTERFACES === "true" ? "0.0.0.0" : "127.0.0.1";
logger.info("Starting Deployments Server ✅", port);
serve({ fetch: app.fetch, port });
serve({ fetch: app.fetch, port, host });
3 changes: 2 additions & 1 deletion apps/dokploy/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DATABASE_URL="postgres://dokploy:amukds4wi9001583845717ad2@localhost:5432/dokploy"
PORT=3000
NODE_ENV=development
NODE_ENV=development
EXPOSE_ALL_INTERFACES=false
28 changes: 27 additions & 1 deletion apps/dokploy/components/dashboard/settings/web-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
import { cn } from "@/lib/utils";
import { api } from "@/utils/api";
import { useTranslation } from "next-i18next";
import React from "react";
import React, { useState } from "react";
import { ShowDokployActions } from "./servers/actions/show-dokploy-actions";
import { ShowStorageActions } from "./servers/actions/show-storage-actions";
import { ShowTraefikActions } from "./servers/actions/show-traefik-actions";
import { ToggleDockerCleanup } from "./servers/actions/toggle-docker-cleanup";
import { UpdateServer } from "./web-server/update-server";
import { Switch } from "@/components/ui/switch";
import { Alert } from "@/components/ui/alert";

interface Props {
className?: string;
Expand All @@ -24,6 +26,14 @@ export const WebServer = ({ className }: Props) => {

const { data: dokployVersion } = api.settings.getDokployVersion.useQuery();

const [exposeAllInterfaces, setExposeAllInterfaces] = useState(
process.env.EXPOSE_ALL_INTERFACES === "true"
);

const handleToggleChange = () => {
setExposeAllInterfaces(!exposeAllInterfaces);
};

return (
<Card className={cn("rounded-lg w-full bg-transparent p-0", className)}>
<CardHeader>
Expand Down Expand Up @@ -53,6 +63,22 @@ export const WebServer = ({ className }: Props) => {

<ToggleDockerCleanup />
</div>

<div className="flex items-center justify-between gap-4">
<span className="text-sm text-muted-foreground">
Expose server port
</span>
<Switch
checked={exposeAllInterfaces}
onCheckedChange={handleToggleChange}
/>
</div>

{exposeAllInterfaces && (
<Alert variant="warning">
{t("settings.server.webServer.exposeWarning")}
</Alert>
)}
</CardContent>
</Card>
);
Expand Down
3 changes: 2 additions & 1 deletion apps/dokploy/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const app = next({ dev, turbopack: process.env.TURBOPACK === "1" });
const handle = app.getRequestHandler();
void app.prepare().then(async () => {
try {
const host = process.env.EXPOSE_ALL_INTERFACES === "true" ? "0.0.0.0" : "127.0.0.1";
const server = http.createServer((req, res) => {
handle(req, res);
});
Expand Down Expand Up @@ -63,7 +64,7 @@ void app.prepare().then(async () => {
await migration();
}

server.listen(PORT);
server.listen(PORT, host);
console.log("Server Started:", PORT);
if (!IS_CLOUD) {
console.log("Starting Deployment Worker");
Expand Down
Loading