Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ”’ Adds optional DISABLE_PROXY_ENDPOINTS env var, to disable proxy endpoints

Alicia Sykes87bd2f09b00b
diff --git a/docs/management.md b/docs/management.md
index 7cabe382..d0fe339c 100644
--- a/docs/management.md
+++ b/docs/management.md
@@ -359,6 +359,8 @@ When Dashy runs in server mode (the default Docker setup), it exposes several AP
The CORS proxy (`/cors-proxy`) is worth calling out specifically: it forwards requests from the Dashy server to external URLs, so widgets can reach APIs that don't set CORS headers. On a private network this is harmless, but on an internet-exposed instance without auth, it could be abused as an open proxy. Always enable authentication if your instance is reachable from untrusted networks.
+If you don't use widgets or status checks, you can disable the endpoints which make outbound requests (`/status-check`, `/ping-check` and `/cors-proxy`) entirely, by setting the `DISABLE_PROXY_ENDPOINTS=true` environmental variable. They will then respond with a 403 error, and never make an external request.
+
**[⬆️ Back to Top](#management)**
---
diff --git a/services/app.js b/services/app.js
index f957938b..18aae180 100644
--- a/services/app.js
+++ b/services/app.js
@@ -216,6 +216,12 @@ function requireAdmin(req, res, next) {
/* A middleware function for Connect, that filters requests based on method type */
const method = (m, mw) => (req, res, next) => (req.method === m ? mw(req, res, next) : next());
+/* Kill switch for endpoints that make outbound requests (DISABLE_PROXY_ENDPOINTS=true) */
+const proxyEndpointsGate = (req, res, next) => {
+ if (process.env.DISABLE_PROXY_ENDPOINTS !== 'true') return next();
+ return res.status(403).json({ error: 'This feature has been disabled by your administrator' });
+};
+
const app = express()
.get(ENDPOINTS.health, (req, res) => {
res.set('Cache-Control', 'no-store').status(200).json({
@@ -229,7 +235,7 @@ const app = express()
// Load middlewares for parsing JSON, and supporting HTML5 history routing
.use(express.json({ limit: '1mb' }))
// GET endpoint to run status of a given URL with GET request
- .use(ENDPOINTS.statusCheck, protectConfig, requireAuth, method('GET', (req, res) => {
+ .use(ENDPOINTS.statusCheck, proxyEndpointsGate, protectConfig, requireAuth, method('GET', (req, res) => {
try {
statusCheck(req.url, (results) => {
if (!res.headersSent) {
@@ -245,7 +251,7 @@ const app = express()
}
}))
// GET endpoint to run ping of a given URL with GET request
- .use(ENDPOINTS.pingCheck, protectConfig, requireAuth, method('GET', (req, res) => {
+ .use(ENDPOINTS.pingCheck, proxyEndpointsGate, protectConfig, requireAuth, method('GET', (req, res) => {
try {
pingCheck(req.url, (results) => {
if (!res.headersSent) {
@@ -285,7 +291,7 @@ const app = express()
}
}))
// GET for accessing non-CORS API services
- .use(ENDPOINTS.corsProxy, protectConfig, requireAuth, (req, res) => {
+ .use(ENDPOINTS.corsProxy, proxyEndpointsGate, protectConfig, requireAuth, (req, res) => {
try {
corsProxy(req, res);
} catch (e) {