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!

πŸ” Security fix for encoded YAML URLs

Alicia Sykes3bcc2e4571cb
diff --git a/services/app.js b/services/app.js
index 67341533..25acb704 100644
--- a/services/app.js
+++ b/services/app.js
@@ -32,6 +32,7 @@ const pingCheck = require('./endpoints/ping-check'); // Used by the ping check f
const saveConfig = require('./endpoints/save-config'); // Saves users new conf.yml to file-system
const systemInfo = require('./endpoints/system-info'); // Basic system info, for resource widget
const sslServer = require('./utils/ssl-server'); // TLS-enabled web server
+const blockStaticYaml = require('./utils/block-static-yaml'); // Keeps YAML out of static serving
const corsProxy = require('./endpoints/cors-proxy'); // Enables API requests to CORS-blocked services
const getUser = require('./endpoints/get-user'); // Enables server side user lookup
const openSearch = require('./endpoints/opensearch'); // Descriptor for browser keyword search
@@ -373,7 +374,8 @@ const app = express()
if (err) safeEnd(res, errBody(`Could not read ${ymlFile}`), 404);
});
})
- // Serves up static files
+ // Serves up static files, except YAML (handled above)
+ .use(blockStaticYaml)
.use(express.static(path.resolve(rootDir, process.env.USER_DATA_DIR || 'user-data')))
.use(express.static(path.join(rootDir, 'dist')))
.use(express.static(path.join(rootDir, 'public'), { index: 'initialization.html' }))
diff --git a/services/utils/block-static-yaml.js b/services/utils/block-static-yaml.js
new file mode 100644
index 00000000..5ee6927d
--- /dev/null
+++ b/services/utils/block-static-yaml.js
@@ -0,0 +1,11 @@
+/**
+ * Express middleware function which stope static from serving YAML paths
+ */
+const path = require('path');
+
+module.exports = (req, res, next) => {
+ let file;
+ try { file = path.normalize(decodeURIComponent(req.path)); } catch (e) { return next(); }
+ if (!/\.(ya?ml|yam)(:|$)/i.test(file)) return next();
+ return res.status(404).json({ success: false, message: 'Not Found' });
+};
diff --git a/tests/server/conf-strip.test.js b/tests/server/conf-strip.test.js
index ff433465..95144144 100644
--- a/tests/server/conf-strip.test.js
+++ b/tests/server/conf-strip.test.js
@@ -78,6 +78,10 @@ describe('OIDC strip behaviour for /conf.yml', () => {
expect(res.status).toBe(401);
});
+ it.each(['/conf%2Eyml', '/sub.ya%6Dl', '/sub.yml%2F.'])('does not serve %s via static', async (url) => {
+ expect((await request(app).get(url)).status).toBe(404);
+ });
+
it('falls through to bootstrap on conf.yml when Bearer fails to verify', async () => {
const res = await request(app)
.get('/conf.yml')