Skip to content

Commit 61aa66e

Browse files
authored
Merge pull request #272 from italia/fix-metadata-url-check
fix: add metadata url check
2 parents 414e2b7 + 7b3165f commit 61aa66e

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

spid-validator/server/lib/utils.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const url = require("url");
22
const path = require("path");
3+
const https = require("https");
34
const CircularJSON = require("circular-json");
45
const child_process = require('child_process');
56
const UUID = require("uuidjs");
@@ -56,6 +57,19 @@ class Utils {
5657

5758
static metadataDownload(src, dest) {
5859
return new Promise((resolve, reject) => {
60+
61+
// check if URL is valid
62+
if(!this.isValidUrl(src)) {
63+
return reject("Inserire una URL valida");
64+
}
65+
66+
// check if URL exists
67+
https.get(src, (res) => {
68+
if(res.statusCode!='200') {
69+
return reject("Metadata non trovato alla URL indicata");
70+
}
71+
})
72+
5973
const file_name = url.parse(src).pathname.split('/').pop();
6074
const file_extention = path.extname(file_name);
6175
const cmd = 'wget -O "' + dest + '" "' + src + '" --no-check-certificate --no-cache --no-cookies --user-agent="Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"';
@@ -211,6 +225,20 @@ class Utils {
211225
});
212226
return fileArray;
213227
}
228+
229+
static isValidUrl(str) {
230+
const pattern = new RegExp(
231+
'^([a-zA-Z]+:\\/\\/)?' + // protocol
232+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
233+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR IP (v4) address
234+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
235+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
236+
'(\\#[-a-z\\d_]*)?$', // fragment locator
237+
'i'
238+
);
239+
return pattern.test(str);
240+
}
241+
214242
}
215243

216244
module.exports = Utils;

spid-validator/server/npm-shrinkwrap.json_original

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spid-validator/server/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spid-validator",
3-
"version": "1.10.4",
3+
"version": "1.10.5",
44
"description": "Tool for validating Service Provider compliance to SPID response from Identity Provider",
55
"main": "spid-validator",
66
"author": "Michele D'Amico (damikael) - AgID",
@@ -26,8 +26,9 @@
2626
"unzip": "^0.1.11",
2727
"upload": "^1.3.2",
2828
"uuidjs": "^4.0.3",
29-
"xml-encryption": "^0.11.1",
30-
"xmlbuilder": "^9.0.7",
29+
"xml-encryption": "^3.0.2",
30+
"xmlbuilder": "^15.1.1",
31+
"xmldom": "^0.6.0",
3132
"xpath": "0.0.27",
3233
"xpath.js": "^1.1.0"
3334
}

0 commit comments

Comments
 (0)