@blazedpath/commons 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/blz-base/health/index.js +215 -0
- package/blz-base/index.js +1466 -0
- package/blz-cache/LruCache.js +44 -0
- package/blz-cache/index.js +29 -0
- package/blz-config/index.js +434 -0
- package/blz-core/index.js +364 -0
- package/blz-cryptography/index.js +54 -0
- package/blz-datetimes/index.js +356 -0
- package/blz-file/example.dat +2545 -0
- package/blz-file/fileService.js +205 -0
- package/blz-file/index.js +94 -0
- package/blz-file/index.test.js +31 -0
- package/blz-file/lab.js +33 -0
- package/blz-hazelcast/index.js +189 -0
- package/blz-hazelcast/lib/credentials.js +25 -0
- package/blz-hazelcast/lib/credentialsFactory.js +12 -0
- package/blz-hazelcast/lib/hazelcastCache.js +234 -0
- package/blz-iterable/index.js +446 -0
- package/blz-json-schema/index.js +11 -0
- package/blz-jwt/index.js +121 -0
- package/blz-kafka/index.js +522 -0
- package/blz-math/index.js +131 -0
- package/blz-mongodb/index.js +326 -0
- package/blz-rds/__test__/scape.test.js +58 -0
- package/blz-rds/blz-rds-executor.js +578 -0
- package/blz-rds/blz-rds-helper.js +310 -0
- package/blz-rds/commands/core/add.js +13 -0
- package/blz-rds/commands/core/and.js +18 -0
- package/blz-rds/commands/core/asc.js +10 -0
- package/blz-rds/commands/core/avg.js +10 -0
- package/blz-rds/commands/core/column-ref.js +8 -0
- package/blz-rds/commands/core/count-distinct.js +10 -0
- package/blz-rds/commands/core/count.js +10 -0
- package/blz-rds/commands/core/decimal.js +8 -0
- package/blz-rds/commands/core/desc.js +10 -0
- package/blz-rds/commands/core/distinct.js +10 -0
- package/blz-rds/commands/core/divide.js +11 -0
- package/blz-rds/commands/core/embedded-exists.js +17 -0
- package/blz-rds/commands/core/embedded-select.js +17 -0
- package/blz-rds/commands/core/equals.js +9 -0
- package/blz-rds/commands/core/false.js +8 -0
- package/blz-rds/commands/core/greater-or-equal.js +9 -0
- package/blz-rds/commands/core/greater.js +9 -0
- package/blz-rds/commands/core/in.js +9 -0
- package/blz-rds/commands/core/integer.js +8 -0
- package/blz-rds/commands/core/is-not-null.js +11 -0
- package/blz-rds/commands/core/is-null-or-value.js +10 -0
- package/blz-rds/commands/core/is-null.js +11 -0
- package/blz-rds/commands/core/less-or-equal.js +9 -0
- package/blz-rds/commands/core/less-unary.js +12 -0
- package/blz-rds/commands/core/less.js +9 -0
- package/blz-rds/commands/core/like.js +12 -0
- package/blz-rds/commands/core/max.js +10 -0
- package/blz-rds/commands/core/min.js +10 -0
- package/blz-rds/commands/core/multiply.js +13 -0
- package/blz-rds/commands/core/not-equals.js +9 -0
- package/blz-rds/commands/core/not-in.js +9 -0
- package/blz-rds/commands/core/not.js +13 -0
- package/blz-rds/commands/core/null.js +8 -0
- package/blz-rds/commands/core/nvl.js +11 -0
- package/blz-rds/commands/core/or.js +13 -0
- package/blz-rds/commands/core/parameter.js +34 -0
- package/blz-rds/commands/core/remainder.js +16 -0
- package/blz-rds/commands/core/string.js +8 -0
- package/blz-rds/commands/core/subtract.js +13 -0
- package/blz-rds/commands/core/sum.js +10 -0
- package/blz-rds/commands/core/true.js +8 -0
- package/blz-rds/commands/core/tuple.js +13 -0
- package/blz-rds/commands/datetimes/add-days.js +11 -0
- package/blz-rds/commands/datetimes/add-hours.js +11 -0
- package/blz-rds/commands/datetimes/add-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/add-minutes.js +11 -0
- package/blz-rds/commands/datetimes/add-months.js +11 -0
- package/blz-rds/commands/datetimes/add-seconds.js +11 -0
- package/blz-rds/commands/datetimes/add-years.js +11 -0
- package/blz-rds/commands/datetimes/date-diff.js +11 -0
- package/blz-rds/commands/datetimes/date.js +12 -0
- package/blz-rds/commands/datetimes/datetime-diff.js +11 -0
- package/blz-rds/commands/datetimes/datetime.js +15 -0
- package/blz-rds/commands/datetimes/day.js +10 -0
- package/blz-rds/commands/datetimes/hour.js +10 -0
- package/blz-rds/commands/datetimes/millisecond.js +10 -0
- package/blz-rds/commands/datetimes/minute.js +10 -0
- package/blz-rds/commands/datetimes/month-text.js +10 -0
- package/blz-rds/commands/datetimes/month.js +10 -0
- package/blz-rds/commands/datetimes/now.js +9 -0
- package/blz-rds/commands/datetimes/second.js +10 -0
- package/blz-rds/commands/datetimes/subtract-days.js +11 -0
- package/blz-rds/commands/datetimes/subtract-hours.js +11 -0
- package/blz-rds/commands/datetimes/subtract-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/subtract-minutes.js +11 -0
- package/blz-rds/commands/datetimes/subtract-seconds.js +11 -0
- package/blz-rds/commands/datetimes/time-diff.js +11 -0
- package/blz-rds/commands/datetimes/time.js +13 -0
- package/blz-rds/commands/datetimes/today.js +9 -0
- package/blz-rds/commands/datetimes/week-day-text.js +10 -0
- package/blz-rds/commands/datetimes/week-day.js +10 -0
- package/blz-rds/commands/datetimes/week.js +10 -0
- package/blz-rds/commands/datetimes/year.js +10 -0
- package/blz-rds/commands/math/abs.js +10 -0
- package/blz-rds/commands/math/acos.js +10 -0
- package/blz-rds/commands/math/asin.js +10 -0
- package/blz-rds/commands/math/atan.js +10 -0
- package/blz-rds/commands/math/atan2.js +11 -0
- package/blz-rds/commands/math/ceil.js +10 -0
- package/blz-rds/commands/math/cos.js +10 -0
- package/blz-rds/commands/math/cosh.js +10 -0
- package/blz-rds/commands/math/exp.js +10 -0
- package/blz-rds/commands/math/floor.js +10 -0
- package/blz-rds/commands/math/log.js +18 -0
- package/blz-rds/commands/math/log10.js +10 -0
- package/blz-rds/commands/math/pow.js +11 -0
- package/blz-rds/commands/math/random.js +9 -0
- package/blz-rds/commands/math/round.js +18 -0
- package/blz-rds/commands/math/sign.js +10 -0
- package/blz-rds/commands/math/sin.js +10 -0
- package/blz-rds/commands/math/sinh.js +10 -0
- package/blz-rds/commands/math/sqrt.js +10 -0
- package/blz-rds/commands/math/tan.js +10 -0
- package/blz-rds/commands/math/tanh.js +10 -0
- package/blz-rds/commands/math/trunc.js +18 -0
- package/blz-rds/commands/strings/concat.js +20 -0
- package/blz-rds/commands/strings/contains.js +12 -0
- package/blz-rds/commands/strings/ends-with.js +12 -0
- package/blz-rds/commands/strings/index-of.js +11 -0
- package/blz-rds/commands/strings/is-null-or-empty.js +11 -0
- package/blz-rds/commands/strings/is-null-or-white-space.js +11 -0
- package/blz-rds/commands/strings/join.js +22 -0
- package/blz-rds/commands/strings/last-index-of.js +11 -0
- package/blz-rds/commands/strings/length.js +10 -0
- package/blz-rds/commands/strings/pad-left.js +20 -0
- package/blz-rds/commands/strings/pad-right.js +20 -0
- package/blz-rds/commands/strings/replace.js +12 -0
- package/blz-rds/commands/strings/starts-with.js +12 -0
- package/blz-rds/commands/strings/substring.js +12 -0
- package/blz-rds/commands/strings/to-lower.js +10 -0
- package/blz-rds/commands/strings/to-upper.js +10 -0
- package/blz-rds/commands/strings/trim-end.js +10 -0
- package/blz-rds/commands/strings/trim-start.js +10 -0
- package/blz-rds/commands/strings/trim.js +10 -0
- package/blz-rds/index.js +744 -0
- package/blz-rds-mysql/base.js +857 -0
- package/blz-rds-mysql/connection-manager.js +129 -0
- package/blz-rds-mysql/execute-bulk-insert.js +35 -0
- package/blz-rds-mysql/execute-bulk-merge.js +45 -0
- package/blz-rds-mysql/execute-non-query.js +34 -0
- package/blz-rds-mysql/execute-query.js +50 -0
- package/blz-rds-mysql/index.js +41 -0
- package/blz-rds-mysql/stored-procedure.js +207 -0
- package/blz-rds-mysql/syntaxis.json +114 -0
- package/blz-rds-mysqlx/base.js +846 -0
- package/blz-rds-mysqlx/connection-manager.js +141 -0
- package/blz-rds-mysqlx/execute-bulk-insert.js +35 -0
- package/blz-rds-mysqlx/execute-bulk-merge.js +45 -0
- package/blz-rds-mysqlx/execute-non-query.js +29 -0
- package/blz-rds-mysqlx/execute-query.js +39 -0
- package/blz-rds-mysqlx/index.js +41 -0
- package/blz-rds-mysqlx/stored-procedure.js +179 -0
- package/blz-rds-mysqlx/syntaxis.json +105 -0
- package/blz-rds-oracle/index.js +540 -0
- package/blz-rds-oracle/syntaxis.json +112 -0
- package/blz-rds-postgres/base.js +861 -0
- package/blz-rds-postgres/connection-manager.js +225 -0
- package/blz-rds-postgres/execute-bulk-insert.js +81 -0
- package/blz-rds-postgres/execute-bulk-merge.js +93 -0
- package/blz-rds-postgres/execute-non-query.js +23 -0
- package/blz-rds-postgres/execute-query.js +37 -0
- package/blz-rds-postgres/index.js +41 -0
- package/blz-rds-postgres/result-set.js +51 -0
- package/blz-rds-postgres/stored-procedure.js +116 -0
- package/blz-rds-postgres/syntaxis.json +114 -0
- package/blz-redis/index.js +217 -0
- package/blz-redis/lib/redisCache.js +265 -0
- package/blz-regex/index.js +25 -0
- package/blz-security/.eslintrc.js +15 -0
- package/blz-security/__test__/AuthorizationKpn.yaml +1043 -0
- package/blz-security/__test__/FinancingSetting.yaml +177 -0
- package/blz-security/__test__/KpnConfigPortal.yaml +330 -0
- package/blz-security/__test__/OrderManagement.yaml +5190 -0
- package/blz-security/__test__/Security.yaml +128 -0
- package/blz-security/__test__/autorization.test.js +105 -0
- package/blz-security/__test__/orderManagement.test.js +26 -0
- package/blz-security/__test__/secureUrl.test.js +79 -0
- package/blz-security/__test__/solveMergeRule.test.js +109 -0
- package/blz-security/__test__/sqlInjectionGuard.test.js +203 -0
- package/blz-security/__test__/xssGuard.test.js +204 -0
- package/blz-security/authorizationService.js +536 -0
- package/blz-security/config/global.js +8 -0
- package/blz-security/config/welcome +8 -0
- package/blz-security/doc/README.md +75 -0
- package/blz-security/filescanner/index.js +46 -0
- package/blz-security/helpers/consts.js +229 -0
- package/blz-security/helpers/utils.js +267 -0
- package/blz-security/implementations/cache.js +90 -0
- package/blz-security/implementations/oidc.js +404 -0
- package/blz-security/implementations/pkceCacheStore.js +23 -0
- package/blz-security/implementations/saml.js +10 -0
- package/blz-security/implementations/uma.js +63 -0
- package/blz-security/implementations/webAuthn.js +9 -0
- package/blz-security/implementations/wstg.js +72 -0
- package/blz-security/index.js +77 -0
- package/blz-security/lab/index.js +27 -0
- package/blz-security/middleware/HapiServerAzureAd.js +641 -0
- package/blz-security/middleware/HapiServerKeycloak.js +840 -0
- package/blz-security/middleware/HapiServerSimToken.js +247 -0
- package/blz-security/middleware/hapi.js +515 -0
- package/blz-security/middleware/hapiServer.js +974 -0
- package/blz-security/navigationMemoryRepository.js +15 -0
- package/blz-security/navigationMongoDbRepository.js +73 -0
- package/blz-security/secureUrlService.js +47 -0
- package/blz-security/securityService.js +409 -0
- package/blz-security/sqlInjectionGuard.js +162 -0
- package/blz-security/templates/forbidden.html +0 -0
- package/blz-security/templates/session-iframe-azure-ad.html +7 -0
- package/blz-security/templates/session-iframe.html +73 -0
- package/blz-security/templates/unauthorized.html +1 -0
- package/blz-security/xssGuard.js +87 -0
- package/blz-strings/index.js +167 -0
- package/blz-uuid/index.js +7 -0
- package/blz-yaml/index.js +19 -0
- package/index.js +84 -0
- package/package.json +97 -0
- package/process-managers/index.js +422 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
module.exports = class SqlInjectionGuard {
|
|
3
|
+
constructor(logger = console) {
|
|
4
|
+
this.logger = logger;
|
|
5
|
+
this._initialized = false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
_initialize() {
|
|
9
|
+
if (this._initialized) return;
|
|
10
|
+
this._initialized = true;
|
|
11
|
+
const allowedPatternsEnv = process.env.blz_securityApiSanitizeAllowedSqlInputPatterns;
|
|
12
|
+
const paramPatternsEnv = process.env.blz_securityApiSanitizeDangerousParamPatterns;
|
|
13
|
+
const sqlPatternsEnv = process.env.blz_securityApiSanitizeDangerousSqlPatterns;
|
|
14
|
+
this.onlyLog = process.env.blz_securityApiSanitizeOnlyLog === 'true';
|
|
15
|
+
const parseRegexArray = (input) => {
|
|
16
|
+
try {
|
|
17
|
+
if (input == undefined || input == null) return null
|
|
18
|
+
const rawList = JSON.parse(input); // must be an array of strings type ["--", "\\bselect\\b.+\\bfrom\\b"]
|
|
19
|
+
return rawList.map(pattern => new RegExp(pattern, 'i'));
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
this.dangerousParamPatterns =
|
|
25
|
+
parseRegexArray(paramPatternsEnv) || [
|
|
26
|
+
/--/i,
|
|
27
|
+
/\/\*/i,
|
|
28
|
+
/\*\//i,
|
|
29
|
+
/\bor\b\s+\w+\s*=/i,
|
|
30
|
+
/\bor\b\s+.*?=.*?/i,
|
|
31
|
+
/\bor\b\s+'.*?'\s*=\s*'.*?'/i,
|
|
32
|
+
/\bor\b\s+\w+\s*like/i,
|
|
33
|
+
/\band\b\s+\w+\s*=/i,
|
|
34
|
+
/\band\b\s+\w+\s*like/i,
|
|
35
|
+
/\bselect\b[\s\S]+?\bfrom\b/i,
|
|
36
|
+
/\bunion\s+select\b/i,
|
|
37
|
+
/\bdrop\s+table\b/i,
|
|
38
|
+
/\binsert\s+into\b/i,
|
|
39
|
+
/\bupdate\b\s+\w+\s+\bset\b[\s\S]*?=/i,
|
|
40
|
+
/\bdelete\s+from\b/i,
|
|
41
|
+
/\bpg_sleep\s*\(/i,
|
|
42
|
+
/\bdbms_lock\.sleep\s*\(/i,
|
|
43
|
+
/\bexec\s*\(/i,
|
|
44
|
+
/\bexecute\s*\(/i
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
this.dangerousSqlPatterns =
|
|
48
|
+
parseRegexArray(sqlPatternsEnv) || [
|
|
49
|
+
/;\s*drop\b/i,
|
|
50
|
+
/;\s*truncate\b/i,
|
|
51
|
+
/\bpg_sleep\s*\(/i,
|
|
52
|
+
/\bdbms_lock\.sleep\s*\(/i,
|
|
53
|
+
/\bexec(ute)?\s*(\(|\s)/i,
|
|
54
|
+
/\binformation_schema\b/i,
|
|
55
|
+
/\bpg_catalog\b/i,
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
this.allowedInputPatterns =
|
|
59
|
+
parseRegexArray(allowedPatternsEnv) || [
|
|
60
|
+
new RegExp('^[^<>]*<$', 'i'),
|
|
61
|
+
new RegExp('^>[^<>]*$', 'i')
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// Define a schema for each param object
|
|
66
|
+
this.paramSchema = z.object({
|
|
67
|
+
name: z.string(),
|
|
68
|
+
value: z.any(), // value can be string, number, etc.
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Schema for the full list
|
|
72
|
+
this.paramsSchema = z.array(this.paramSchema);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
isAllowedByWhitelist(value) {
|
|
76
|
+
return this.allowedInputPatterns.some(pattern => pattern.test(value));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
validateParamValue(name, value) {
|
|
80
|
+
this. _initialize()
|
|
81
|
+
if (typeof value !== 'string') return;
|
|
82
|
+
const trimmed = value.trim();
|
|
83
|
+
if (this.isAllowedByWhitelist(trimmed)) return
|
|
84
|
+
// Always check for dangerous SQL injection patterns
|
|
85
|
+
for (const pattern of this.dangerousParamPatterns) {
|
|
86
|
+
if (pattern.test(trimmed)) {
|
|
87
|
+
const message = `Potential SQL injection in parameter "${name}": ${value}`;
|
|
88
|
+
if (this.onlyLog) {
|
|
89
|
+
this.logger?.warn?.(`[SQLInjectionGuard] ${message}`);
|
|
90
|
+
} else {
|
|
91
|
+
const err = new Error('Potential SQL injection');
|
|
92
|
+
err.code = 'SQLInjection';
|
|
93
|
+
err.data = message;
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
validateParamList(params) {
|
|
101
|
+
this. _initialize()
|
|
102
|
+
this.paramsSchema.parse(params); // Validate structure with Zod
|
|
103
|
+
for (const param of params) {
|
|
104
|
+
this.validateParamValue(param.name, param.value);
|
|
105
|
+
}
|
|
106
|
+
return params;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
validateRawSql(sql) {
|
|
110
|
+
this. _initialize()
|
|
111
|
+
if (typeof sql !== 'string') return false;
|
|
112
|
+
for (const pattern of this.dangerousSqlPatterns) {
|
|
113
|
+
if (pattern.test(sql.toLowerCase())) {
|
|
114
|
+
const message = `Potential SQL injection in "${sql}" pattern:${pattern}`;
|
|
115
|
+
if (this.onlyLog) {
|
|
116
|
+
this.logger.warn(`[SQLInjectionGuard] ${message}`);
|
|
117
|
+
} else {
|
|
118
|
+
const err = new Error('Potential SQL injection');
|
|
119
|
+
err.code = 'SQLInjection';
|
|
120
|
+
err.data = message;
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return sql
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
validateObject(obj) {
|
|
129
|
+
this. _initialize()
|
|
130
|
+
const checkValue = (value) => {
|
|
131
|
+
if (typeof value === 'string') {
|
|
132
|
+
const trimmed = value.trim();
|
|
133
|
+
if (!this.isAllowedByWhitelist(trimmed)) {
|
|
134
|
+
for (const pattern of this.dangerousParamPatterns) {
|
|
135
|
+
if (pattern.test(trimmed)) {
|
|
136
|
+
const message = `Value "${value}" violates SQL injection policy.`;
|
|
137
|
+
if (this.onlyLog) {
|
|
138
|
+
this.logger.warn(`[SQLInjectionGuard] ${message}`);
|
|
139
|
+
} else {
|
|
140
|
+
const err = new Error('Potential SQL injection');
|
|
141
|
+
err.code = 'BadRequest';
|
|
142
|
+
err.data = message;
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} else if (Array.isArray(value)) {
|
|
149
|
+
for (const item of value) checkValue(item);
|
|
150
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
151
|
+
for (const key in value) {
|
|
152
|
+
if (Object.hasOwn(value, key)) {
|
|
153
|
+
checkValue(value[key]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
checkValue(obj);
|
|
160
|
+
return obj;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<body onload="javascript:startChecking()">
|
|
4
|
+
<iframe id="iframeOP" title="Session Iframe" src="{{sessionIframeUrl}}" style="display: none"></iframe>
|
|
5
|
+
</body>
|
|
6
|
+
<script>
|
|
7
|
+
let targetRP = new URL('{{sessionIframeUrl}}');
|
|
8
|
+
let previousState = '';
|
|
9
|
+
|
|
10
|
+
function startChecking() {
|
|
11
|
+
previousState = getCookieValue('{{sessionCookiesPrefix}}session_state');
|
|
12
|
+
setInterval(checkStatus, 15e3);
|
|
13
|
+
setInterval(checkSessionStatus, 15e3);
|
|
14
|
+
}
|
|
15
|
+
async function checkSessionStatus() {
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch('/check-session', {
|
|
18
|
+
method: 'GET',
|
|
19
|
+
credentials: 'include' // Include cookies in the request
|
|
20
|
+
});
|
|
21
|
+
const data = await response.json();
|
|
22
|
+
if (data.expired) {
|
|
23
|
+
if (data.redirectUrl) {
|
|
24
|
+
parent.location.href = data.redirectUrl; // redirect sentence
|
|
25
|
+
} else {
|
|
26
|
+
parent.location.reload(); // Reload the parent page instead of just the iframe
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('Error validating token:', error);
|
|
31
|
+
// Optionally handle the error
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function getCookieValue(cookieName) {
|
|
35
|
+
let name = cookieName + '=';
|
|
36
|
+
let cookies = document.cookie.split(';');
|
|
37
|
+
if (!cookies) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
41
|
+
let cookie = cookies[i].trim();
|
|
42
|
+
if (cookie.indexOf(name) == 0) {
|
|
43
|
+
return cookie.substring(name.length, cookie.length);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function checkStatus() {
|
|
50
|
+
let client = '{{clientId}}';
|
|
51
|
+
const prefix = '{{sessionCookiesPrefix}}'
|
|
52
|
+
let sessionState = getCookieValue(prefix + 'session_state');
|
|
53
|
+
let message = client + ' ' + sessionState;
|
|
54
|
+
const iframe = document.getElementById('iframeOP');
|
|
55
|
+
iframe.contentWindow.postMessage(message, '{{sessionIframeUrl}}');
|
|
56
|
+
//window.frames['iframeOP'].contentWindow.postMessage(message, '{{sessionIframeUrl}}');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
window.addEventListener('message', receiveMessage, false);
|
|
60
|
+
|
|
61
|
+
function receiveMessage(event) {
|
|
62
|
+
if (event.origin !== targetRP.origin) return;
|
|
63
|
+
// To avoid endless reloads, only do a reload when the session state changed
|
|
64
|
+
let currentState = getCookieValue('{{sessionCookiesPrefix}}session_state');
|
|
65
|
+
|
|
66
|
+
if (event.data === 'changed' && previousState !== currentState) {
|
|
67
|
+
previousState = currentState;
|
|
68
|
+
document.cookie = 'session_state' + '=; Max-Age=0; SameSite=None; Secure';
|
|
69
|
+
parent.location.reload();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
</script>
|
|
73
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const { JSDOM } = require('jsdom');
|
|
2
|
+
const createDOMPurify = require('dompurify');
|
|
3
|
+
|
|
4
|
+
module.exports = class XssGuard {
|
|
5
|
+
constructor(logger = console) {
|
|
6
|
+
this.logger = logger;
|
|
7
|
+
const window = new JSDOM('').window;
|
|
8
|
+
this.DOMPurify = createDOMPurify(window);
|
|
9
|
+
this.sanitizeOptions = {
|
|
10
|
+
ALLOWED_TAGS: [], // Does not allow any HTML tags
|
|
11
|
+
ALLOWED_ATTR: [] // No attributes
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
isZipString(str) {
|
|
16
|
+
return str.startsWith('PK\x03\x04');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
isAllowedBlocklyXml(str) {
|
|
20
|
+
const blocklyPatterns = [
|
|
21
|
+
/^<xml[\s\S]*<\/xml>$/i,
|
|
22
|
+
/^<block[\s\S]*<\/block>$/i,
|
|
23
|
+
/^<field name="[\w\-:]+">[\s\S]*<\/field>$/i,
|
|
24
|
+
/^<value name="[\w\-:]+">[\s\S]*<\/value>$/i
|
|
25
|
+
];
|
|
26
|
+
return blocklyPatterns.some((re) => re.test(str));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
sanitizeObject(obj) {
|
|
30
|
+
const sanitizeValue = (value, path = '') => {
|
|
31
|
+
if (value === null)
|
|
32
|
+
return null;
|
|
33
|
+
if (value === undefined )
|
|
34
|
+
return undefined
|
|
35
|
+
|
|
36
|
+
const valueType = toString.call(value);
|
|
37
|
+
if (valueType === '[object String]') {
|
|
38
|
+
|
|
39
|
+
if(this.isZipString(value)){
|
|
40
|
+
return value
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let decoded;
|
|
44
|
+
try {
|
|
45
|
+
decoded = decodeURIComponent(value);
|
|
46
|
+
} catch {
|
|
47
|
+
decoded = value;
|
|
48
|
+
}
|
|
49
|
+
const trimmed = decoded.trim();
|
|
50
|
+
// ⚠️ Skip DOMPurify for valid Blockly XML
|
|
51
|
+
if (this.isAllowedBlocklyXml(trimmed)) {
|
|
52
|
+
return trimmed;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const cleaned = this.DOMPurify.sanitize(trimmed, this.sanitizeOptions);
|
|
57
|
+
|
|
58
|
+
if (cleaned !== trimmed) {
|
|
59
|
+
const message = `Sanitized input at path "${path}". Original: "${trimmed}", Cleaned: "${cleaned}".`;
|
|
60
|
+
this.logger.warn(message);
|
|
61
|
+
}
|
|
62
|
+
return cleaned;
|
|
63
|
+
} else if (valueType === '[object Number]') {
|
|
64
|
+
return value
|
|
65
|
+
} else if (valueType === '[object Boolean]') {
|
|
66
|
+
return value
|
|
67
|
+
} else if (valueType === '[object Date]') {
|
|
68
|
+
return value
|
|
69
|
+
} else if (valueType === '[object Object]' && value.type === 'Buffer' && value.data) {
|
|
70
|
+
return value
|
|
71
|
+
} else if (Array.isArray(value)) {
|
|
72
|
+
return value.map((item, index) => sanitizeValue(item, `${path}[${index}]`));
|
|
73
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
74
|
+
const sanitizedObj = {};
|
|
75
|
+
for (const key in value) {
|
|
76
|
+
if (Object.hasOwn(value, key)) {
|
|
77
|
+
const childPath = path ? `${path}.${key}` : key;
|
|
78
|
+
sanitizedObj[key] = sanitizeValue(value[key], childPath);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return sanitizedObj;
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
};
|
|
85
|
+
return sanitizeValue(obj);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
_internal_: {
|
|
3
|
+
htmlUnescapes: {
|
|
4
|
+
'&': '&',
|
|
5
|
+
'<': '<',
|
|
6
|
+
'>': '>',
|
|
7
|
+
'"': '"',
|
|
8
|
+
''': "'"
|
|
9
|
+
},
|
|
10
|
+
reEscapedHtml: /&(?:amp|lt|gt|quot|#(0+)?39);/g,
|
|
11
|
+
reHasEscapedHtml: RegExp('&(?:amp|lt|gt|quot|#(0+)?39);'),
|
|
12
|
+
htmlEscapes: {
|
|
13
|
+
'&': '&',
|
|
14
|
+
'<': '<',
|
|
15
|
+
'>': '>',
|
|
16
|
+
'"': '"',
|
|
17
|
+
"'": '''
|
|
18
|
+
},
|
|
19
|
+
reUnescapedHtml: /[&<>"']/g,
|
|
20
|
+
reHasUnescapedHtml: RegExp(`[&<>"']`),
|
|
21
|
+
},
|
|
22
|
+
concat: function () {
|
|
23
|
+
let result = '';
|
|
24
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
25
|
+
let argument = arguments[i];
|
|
26
|
+
if (argument !== null)
|
|
27
|
+
result += argument;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
},
|
|
31
|
+
contains: function (target, value) {
|
|
32
|
+
if (target === null || target === undefined)
|
|
33
|
+
return false;
|
|
34
|
+
if (value === null || value === undefined)
|
|
35
|
+
return false;
|
|
36
|
+
return target.indexOf(value) !== -1;
|
|
37
|
+
},
|
|
38
|
+
endsWith: function (target, value) {
|
|
39
|
+
if (target === null || target === undefined)
|
|
40
|
+
return false;
|
|
41
|
+
if (value === null || value === undefined)
|
|
42
|
+
return false;
|
|
43
|
+
return target.substring(target.length - value.length, target.length) === value;
|
|
44
|
+
},
|
|
45
|
+
escapeHtml: function (value) {
|
|
46
|
+
return (value && this._internal_.reHasUnescapedHtml.test(value))
|
|
47
|
+
? value.replace(this._internal_.reUnescapedHtml, (chr) => this._internal_.htmlEscapes[chr])
|
|
48
|
+
: (value || '')
|
|
49
|
+
},
|
|
50
|
+
indexOf: function (target, value) {
|
|
51
|
+
if (target === null || target === undefined)
|
|
52
|
+
return -1;
|
|
53
|
+
if (value === null || value === undefined)
|
|
54
|
+
return -1;
|
|
55
|
+
return target.indexOf(value);
|
|
56
|
+
},
|
|
57
|
+
isNullOrEmpty: function (target) {
|
|
58
|
+
if (target === null || target === undefined)
|
|
59
|
+
return true;
|
|
60
|
+
return (target === '');
|
|
61
|
+
},
|
|
62
|
+
isNullOrWhiteSpace: function (target) {
|
|
63
|
+
if (target === null || target === undefined)
|
|
64
|
+
return true;
|
|
65
|
+
return (target === '' || target.replace(/\s/g, '').length < 1);
|
|
66
|
+
},
|
|
67
|
+
join: function (target, delimiter) {
|
|
68
|
+
if (target === null || target === undefined)
|
|
69
|
+
return null;
|
|
70
|
+
if (delimiter)
|
|
71
|
+
return target.join(delimiter);
|
|
72
|
+
else
|
|
73
|
+
return target.join('');
|
|
74
|
+
},
|
|
75
|
+
lastIndexOf: function (target, value) {
|
|
76
|
+
if (target === null || target === undefined)
|
|
77
|
+
return -1;
|
|
78
|
+
if (value === null || value === undefined)
|
|
79
|
+
return -1;
|
|
80
|
+
return target.lastIndexOf(value);
|
|
81
|
+
},
|
|
82
|
+
length: function (target) {
|
|
83
|
+
if (target === null || target === undefined)
|
|
84
|
+
return 0;
|
|
85
|
+
return target.length;
|
|
86
|
+
},
|
|
87
|
+
padLeft: function (target, totalWidth, padding) {
|
|
88
|
+
if (target === null || target === undefined)
|
|
89
|
+
return null;
|
|
90
|
+
if (totalWidth === null || totalWidth === undefined)
|
|
91
|
+
return target;
|
|
92
|
+
if (padding)
|
|
93
|
+
return target.padStart(totalWidth, padding);
|
|
94
|
+
else
|
|
95
|
+
return target.padStart(totalWidth);
|
|
96
|
+
},
|
|
97
|
+
padRight: function (target, totalWidth, padding) {
|
|
98
|
+
if (target === null || target === undefined)
|
|
99
|
+
return null;
|
|
100
|
+
if (totalWidth === null || totalWidth === undefined)
|
|
101
|
+
return target;
|
|
102
|
+
if (padding)
|
|
103
|
+
return target.padEnd(totalWidth, padding);
|
|
104
|
+
else
|
|
105
|
+
return target.padEnd(totalWidth);
|
|
106
|
+
},
|
|
107
|
+
replace: function (target, oldValue, newValue) {
|
|
108
|
+
if (target === null || target === undefined)
|
|
109
|
+
return null;
|
|
110
|
+
if (oldValue === null || oldValue === undefined)
|
|
111
|
+
return target;
|
|
112
|
+
if (newValue === null || newValue === undefined)
|
|
113
|
+
return target;
|
|
114
|
+
return target.replace(new RegExp(oldValue, 'g'), newValue);
|
|
115
|
+
},
|
|
116
|
+
split: function (target, delimiter) {
|
|
117
|
+
if (target === null || target === undefined)
|
|
118
|
+
return [];
|
|
119
|
+
return target.split(delimiter);
|
|
120
|
+
},
|
|
121
|
+
startsWith: function (target, value) {
|
|
122
|
+
if (target === null || target === undefined)
|
|
123
|
+
return false;
|
|
124
|
+
if (value === null || value === undefined)
|
|
125
|
+
return false;
|
|
126
|
+
return target.substring(0, value.length) === value;
|
|
127
|
+
},
|
|
128
|
+
substring: function (target, startIndex, length) {
|
|
129
|
+
if (target === null || target === undefined)
|
|
130
|
+
return null;
|
|
131
|
+
if (startIndex === null || startIndex === undefined)
|
|
132
|
+
return null;
|
|
133
|
+
if (length === null || length === undefined)
|
|
134
|
+
return null;
|
|
135
|
+
return target.substring(startIndex, startIndex + length);
|
|
136
|
+
},
|
|
137
|
+
toLower: function (target) {
|
|
138
|
+
if (target === null || target === undefined)
|
|
139
|
+
return null;
|
|
140
|
+
return target.toLowerCase();
|
|
141
|
+
},
|
|
142
|
+
toUpper: function (target) {
|
|
143
|
+
if (target === null || target === undefined)
|
|
144
|
+
return null;
|
|
145
|
+
return target.toUpperCase();
|
|
146
|
+
},
|
|
147
|
+
trim: function (target) {
|
|
148
|
+
if (target === null || target === undefined)
|
|
149
|
+
return null;
|
|
150
|
+
return target.trim();
|
|
151
|
+
},
|
|
152
|
+
trimEnd: function (target) {
|
|
153
|
+
if (target === null || target === undefined)
|
|
154
|
+
return null;
|
|
155
|
+
return target.trimEnd();
|
|
156
|
+
},
|
|
157
|
+
trimStart: function (target) {
|
|
158
|
+
if (target === null || target === undefined)
|
|
159
|
+
return null;
|
|
160
|
+
return target.trimStart();
|
|
161
|
+
},
|
|
162
|
+
unescapeHtml: function (value) {
|
|
163
|
+
return (value && this._internal_.reHasEscapedHtml.test(value))
|
|
164
|
+
? value.replace(this._internal_.reEscapedHtml, (entity) => (this._internal_.htmlUnescapes[entity] || "'"))
|
|
165
|
+
: (value || '')
|
|
166
|
+
},
|
|
167
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const jsyaml = require('js-yaml')
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
yamlParse: function (value) {
|
|
5
|
+
if (value === undefined)
|
|
6
|
+
throw new Error('value undefined')
|
|
7
|
+
if (value === null)
|
|
8
|
+
return null
|
|
9
|
+
return jsyaml.load(value)
|
|
10
|
+
},
|
|
11
|
+
yamlStringify: function (value) {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
throw new Error('value undefined')
|
|
14
|
+
if (value === null)
|
|
15
|
+
return null
|
|
16
|
+
else
|
|
17
|
+
return jsyaml.dump(value)
|
|
18
|
+
},
|
|
19
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const BlzBase = require('./blz-base');
|
|
2
|
+
const BlzConfig = require('./blz-config');
|
|
3
|
+
const BlzSecurity = require('./blz-security');
|
|
4
|
+
const FileScanner = require('./blz-security/filescanner/index.js');
|
|
5
|
+
const ProcessManagers = require('./process-managers');
|
|
6
|
+
const { Exception } = require('./blz-security/helpers/utils');
|
|
7
|
+
const BlzCache = require('./blz-cache');
|
|
8
|
+
const BlzCore = require('./blz-core');
|
|
9
|
+
const BlzCryptography = require('./blz-cryptography');
|
|
10
|
+
const BlzDatetimes = require('./blz-datetimes');
|
|
11
|
+
const BlzFile = require('./blz-file');
|
|
12
|
+
const BlzHazelcast = require('./blz-hazelcast');
|
|
13
|
+
const BlzIterable = require('./blz-iterable');
|
|
14
|
+
const BlzJsonSchema = require('./blz-json-schema');
|
|
15
|
+
const BlzJwt = require('./blz-jwt');
|
|
16
|
+
const BlzKafka = require('./blz-kafka');
|
|
17
|
+
const BlzMath = require('./blz-math');
|
|
18
|
+
const BlzMongodb = require('./blz-mongodb');
|
|
19
|
+
// const BlzProcesses = require('./blz-processes');
|
|
20
|
+
const BlzRds = require('./blz-rds');
|
|
21
|
+
const BlzRdsMysql = require('./blz-rds-mysql');
|
|
22
|
+
const BlzRdsMysqlx = require('./blz-rds-mysqlx');
|
|
23
|
+
const BlzRdsOracle = require('./blz-rds-oracle');
|
|
24
|
+
const BlzRdsPostgres = require('./blz-rds-postgres');
|
|
25
|
+
const BlzRedis = require('./blz-redis');
|
|
26
|
+
const BlzRegex = require('./blz-regex');
|
|
27
|
+
const BlzStrings = require('./blz-strings/index.js');
|
|
28
|
+
const BlzUuid = require('./blz-uuid');
|
|
29
|
+
const BlzYaml = require('./blz-yaml');
|
|
30
|
+
const { getHealthStatus } = require('./blz-base/health/index.js');
|
|
31
|
+
|
|
32
|
+
const rdsProvider = function(providerName){
|
|
33
|
+
return require('./blz-rds-' + providerName.toLowerCase() + '/index.js')
|
|
34
|
+
}
|
|
35
|
+
const getModulesNames = () => {
|
|
36
|
+
return [
|
|
37
|
+
'blz-base', 'blz-cache', 'blz-config', 'blz-core',
|
|
38
|
+
'blz-cryptography', 'blz-datetimes', 'blz-file',
|
|
39
|
+
'blz-hazelcast', 'blz-iterable', 'blz-json-schema',
|
|
40
|
+
'blz-jwt', 'blz-kafka', 'blz-math', 'blz-mongodb',
|
|
41
|
+
'blz-rds', 'blz-rds-mysql', 'blz-rds-mysqlx', 'blz-rds-oracle',
|
|
42
|
+
'blz-rds-postgres', 'blz-redis', 'blz-regex', 'blz-security',
|
|
43
|
+
'blz-strings', 'blz-uuid', 'blz-yaml'
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
const getVersion = () => {
|
|
47
|
+
const pkg = require('./package.json');
|
|
48
|
+
return pkg.version || 'unknown';
|
|
49
|
+
}
|
|
50
|
+
module.exports = {
|
|
51
|
+
BlzBase,
|
|
52
|
+
BlzConfig,
|
|
53
|
+
BlzSecurity,
|
|
54
|
+
ProcessManagers,
|
|
55
|
+
Exception,
|
|
56
|
+
BlzCache,
|
|
57
|
+
BlzCore,
|
|
58
|
+
BlzCryptography,
|
|
59
|
+
BlzDatetimes,
|
|
60
|
+
BlzFile,
|
|
61
|
+
BlzHazelcast,
|
|
62
|
+
BlzIterable,
|
|
63
|
+
BlzJsonSchema,
|
|
64
|
+
BlzJwt,
|
|
65
|
+
BlzKafka,
|
|
66
|
+
BlzMath,
|
|
67
|
+
BlzMongodb,
|
|
68
|
+
// BlzProcesses,
|
|
69
|
+
BlzRds,
|
|
70
|
+
BlzRdsMysql,
|
|
71
|
+
BlzRdsMysqlx,
|
|
72
|
+
BlzRdsOracle,
|
|
73
|
+
BlzRdsPostgres,
|
|
74
|
+
BlzRedis,
|
|
75
|
+
BlzRegex,
|
|
76
|
+
BlzStrings,
|
|
77
|
+
BlzUuid,
|
|
78
|
+
BlzYaml,
|
|
79
|
+
getHealthStatus,
|
|
80
|
+
FileScanner,
|
|
81
|
+
rdsProvider,
|
|
82
|
+
getModulesNames,
|
|
83
|
+
getVersion
|
|
84
|
+
};
|