Skip to content

Commit 844c5bc

Browse files
authored
Enhance URL safety checks by sanitizing URLs (#444)
* Enhance URL safety checks * Release 1.3.21 - Enhance URL safety checks by sanitizing URLs
1 parent 9052133 commit 844c5bc

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v1.3.21 - 2025-01-09
4+
5+
- ⚙️ **Fix**: Enhance URL safety checks by sanitizing urls first.
6+
37
## v1.3.20 - 2024-11-28
48

59
- 🛡️ **Security**: Update `jsonpath-plus` to version 10.2.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "grafana-json-datasource",
3-
"version": "1.3.20",
3+
"version": "1.3.21",
44
"description": "A data source plugin for loading JSON APIs into Grafana",
55
"keywords": [
66
"grafana",

src/api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default class Api {
160160

161161
function isSafeURL(origUrl: string) {
162162
// browsers interpret backslash as slash
163-
const url = origUrl.replace(/\\/g, '/');
163+
const url = decodeURIComponent(origUrl.replace(/\\/g, '/'));
164164
if (url.endsWith('/..')) {
165165
return false;
166166
}
@@ -173,5 +173,9 @@ function isSafeURL(origUrl: string) {
173173
return false;
174174
}
175175

176+
if (url.includes('\t')) {
177+
return false;
178+
}
179+
176180
return true;
177181
}

src/datasource.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ describe('datasource', () => {
5353
'\\..\\../',
5454
'/../..?',
5555
'\\../..?',
56+
'..%2F..%2f..%2F..%2F..%2F..%2Fapi/', // Make sure that encoded paths are also not allowed
57+
'.%09.%2f.%09.%2f.%09.%2f.%09.%2fapi/', // Make sure that tabs are also not allowed
5658
];
5759

5860
for (let path of badPaths) {

0 commit comments

Comments
 (0)