-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidateGlobal.js
84 lines (67 loc) · 2.18 KB
/
validateGlobal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { propertyPlaceholderRegEx } = require("./constants");
const assert = require("./assert");
const expectedTlsContext = "clientTlsContext";
const validateGlobal = (contents, xml) => {
assert.isTrue(
!contents.includes("<db:dynamic-query>"),
"Global: Dynamic query is not permitted - vulnerable to SQL injection"
);
assert.isTrue(
xml.mule["api-platform-gw:api"] &&
xml.mule["api-platform-gw:api"][0]["$"]["doc:name"] ===
"API Autodiscovery",
"Global: API Autodiscovery not configured"
);
let requestConfigs = xml.mule["http:request-config"];
if (requestConfigs) {
requestConfigs.forEach(requestConfig => {
let requestConfigAttributes = requestConfig["$"];
let protocol = requestConfigAttributes.protocol;
let host = requestConfigAttributes["host"];
let usesMockService = host && host.includes("mock");
if (usesMockService) {
return; // continue forEach, skip remaining checks
}
if (protocol === "HTTPS") {
let tlsContext = requestConfigAttributes["tlsContext-ref"];
assert.equals(
expectedTlsContext,
tlsContext,
`Global ${requestConfigAttributes.name} tlsContext`
);
}
assert.matches(
propertyPlaceholderRegEx,
requestConfigAttributes.host,
`Global ${requestConfigAttributes.name} host`
);
assert.matches(
propertyPlaceholderRegEx,
requestConfigAttributes.port,
`Global ${requestConfigAttributes.name} port`
);
});
}
let templateQueries = xml.mule["db:template-query"];
if (templateQueries) {
templateQueries.forEach(templateQuery => {
let query = templateQuery["db:parameterized-query"];
if (query) {
let queryAttributes = query[0]["$"];
let isFileQuery = queryAttributes && queryAttributes.file;
assert.isTrue(
isFileQuery,
"Global: Inline SQL should be moved to file"
);
if (isFileQuery) {
assert.matches(
/^sql\//,
queryAttributes.file,
"Global: Database query file"
);
}
}
});
}
};
module.exports = validateGlobal;