From be6ccb35e750b47bb121ab12ea53144017ab9650 Mon Sep 17 00:00:00 2001 From: vcwai Date: Sun, 23 Oct 2022 16:00:35 +0800 Subject: [PATCH] Prevent path traversal --- lib/sensor/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sensor/index.js b/lib/sensor/index.js index 5c19843..12065e8 100644 --- a/lib/sensor/index.js +++ b/lib/sensor/index.js @@ -58,6 +58,10 @@ var getSensorDriver = function (model) { if (!model) { return; } + // Ensure that model is a single path component + if (model.includes(path.sep) || model === '..' || model === '.') { + throw new Error(`invalid ${model}`) + } if (_cachedDrivers[model]) { return _cachedDrivers[model]; }