Skip to content

Commit

Permalink
Enhance URL safety checks by sanitizing URLs (#444)
Browse files Browse the repository at this point in the history
* Enhance URL safety checks

* Release 1.3.21 - Enhance URL safety checks by sanitizing URLs
  • Loading branch information
zoltanbedi authored Jan 9, 2025
1 parent 9052133 commit 844c5bc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.3.21 - 2025-01-09

- ⚙️ **Fix**: Enhance URL safety checks by sanitizing urls first.

## v1.3.20 - 2024-11-28

- 🛡️ **Security**: Update `jsonpath-plus` to version 10.2.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grafana-json-datasource",
"version": "1.3.20",
"version": "1.3.21",
"description": "A data source plugin for loading JSON APIs into Grafana",
"keywords": [
"grafana",
Expand Down
6 changes: 5 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class Api {

function isSafeURL(origUrl: string) {
// browsers interpret backslash as slash
const url = origUrl.replace(/\\/g, '/');
const url = decodeURIComponent(origUrl.replace(/\\/g, '/'));
if (url.endsWith('/..')) {
return false;
}
Expand All @@ -173,5 +173,9 @@ function isSafeURL(origUrl: string) {
return false;
}

if (url.includes('\t')) {
return false;
}

return true;
}
2 changes: 2 additions & 0 deletions src/datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ describe('datasource', () => {
'\\..\\../',
'/../..?',
'\\../..?',
'..%2F..%2f..%2F..%2F..%2F..%2Fapi/', // Make sure that encoded paths are also not allowed
'.%09.%2f.%09.%2f.%09.%2f.%09.%2fapi/', // Make sure that tabs are also not allowed
];

for (let path of badPaths) {
Expand Down

0 comments on commit 844c5bc

Please sign in to comment.