@angular-helpers/security 21.6.2 → 22.1.0
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.
|
@@ -4,6 +4,7 @@ import { injectPlatform, injectWorkerPool } from '@angular-helpers/core';
|
|
|
4
4
|
import { isPlatformBrowser, DOCUMENT } from '@angular/common';
|
|
5
5
|
import { Observable, Subject, fromEvent, merge } from 'rxjs';
|
|
6
6
|
import { throttleTime } from 'rxjs/operators';
|
|
7
|
+
import { Meta } from '@angular/platform-browser';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Builder pattern to construct safe regular expressions
|
|
@@ -974,7 +975,9 @@ class InputSanitizerService {
|
|
|
974
975
|
}
|
|
975
976
|
/**
|
|
976
977
|
* Parses and sanitizes an HTML string, keeping only allowed tags and attributes.
|
|
977
|
-
*
|
|
978
|
+
* Leverages the native browser Sanitizer API (e.g. Element.prototype.setHTML) if available
|
|
979
|
+
* for high-performance execution, falling back to a custom DOMParser implementation on
|
|
980
|
+
* unsupported environments (such as older browsers or SSR).
|
|
978
981
|
*
|
|
979
982
|
* @throws {Error} When called in a non-browser environment.
|
|
980
983
|
*/
|
|
@@ -982,6 +985,43 @@ class InputSanitizerService {
|
|
|
982
985
|
if (!this.isSupported()) {
|
|
983
986
|
throw new Error('sanitizeHtml requires a browser environment (DOMParser unavailable)');
|
|
984
987
|
}
|
|
988
|
+
// 1. Try native Element.prototype.setHTML (modern standard in Firefox 148+, etc.)
|
|
989
|
+
if (typeof Element !== 'undefined' && 'setHTML' in Element.prototype) {
|
|
990
|
+
try {
|
|
991
|
+
const tempDiv = document.createElement('div');
|
|
992
|
+
const config = {
|
|
993
|
+
allowElements: this.allowedTags,
|
|
994
|
+
allowAttributes: this.allowedAttributes,
|
|
995
|
+
};
|
|
996
|
+
try {
|
|
997
|
+
tempDiv.setHTML(input, { sanitizer: config });
|
|
998
|
+
}
|
|
999
|
+
catch {
|
|
1000
|
+
tempDiv.setHTML(input);
|
|
1001
|
+
}
|
|
1002
|
+
return tempDiv.innerHTML;
|
|
1003
|
+
}
|
|
1004
|
+
catch {
|
|
1005
|
+
// Fallback on error
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
// 2. Try older Sanitizer API spec draft (implemented in some Chrome versions)
|
|
1009
|
+
if (typeof window.Sanitizer !== 'undefined') {
|
|
1010
|
+
try {
|
|
1011
|
+
const tempDiv = document.createElement('div');
|
|
1012
|
+
const config = {
|
|
1013
|
+
allowElements: this.allowedTags,
|
|
1014
|
+
allowAttributes: this.allowedAttributes,
|
|
1015
|
+
};
|
|
1016
|
+
const sanitizer = new window.Sanitizer(config);
|
|
1017
|
+
tempDiv.innerHTML = sanitizer.sanitizeToString(input);
|
|
1018
|
+
return tempDiv.innerHTML;
|
|
1019
|
+
}
|
|
1020
|
+
catch {
|
|
1021
|
+
// Fallback on error
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
// 3. Fallback to DOMParser-based allowlist sanitizer
|
|
985
1025
|
return sanitizeHtmlString(input, {
|
|
986
1026
|
allowedTags: this.allowedTags,
|
|
987
1027
|
allowedAttributes: this.allowedAttributes,
|
|
@@ -2064,8 +2104,277 @@ function provideSecureMessage() {
|
|
|
2064
2104
|
return makeEnvironmentProviders([WebCryptoService, SecureMessageService]);
|
|
2065
2105
|
}
|
|
2066
2106
|
|
|
2107
|
+
/**
|
|
2108
|
+
* Serializes a CspDirectives object into a standard CSP policy string.
|
|
2109
|
+
*/
|
|
2110
|
+
function serializeCsp(directives) {
|
|
2111
|
+
const parts = [];
|
|
2112
|
+
for (const [key, val] of Object.entries(directives)) {
|
|
2113
|
+
if (val === undefined || val === null) {
|
|
2114
|
+
continue;
|
|
2115
|
+
}
|
|
2116
|
+
if (typeof val === 'boolean') {
|
|
2117
|
+
if (val) {
|
|
2118
|
+
parts.push(key);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
else if (Array.isArray(val)) {
|
|
2122
|
+
if (val.length > 0) {
|
|
2123
|
+
parts.push(`${key} ${val.join(' ')}`);
|
|
2124
|
+
}
|
|
2125
|
+
else {
|
|
2126
|
+
parts.push(key);
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
else if (typeof val === 'string') {
|
|
2130
|
+
parts.push(`${key} ${val}`);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
return parts.join('; ');
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Parses a CSP policy string into a CspDirectives object.
|
|
2137
|
+
*/
|
|
2138
|
+
function parseCsp(policy) {
|
|
2139
|
+
const directives = {};
|
|
2140
|
+
const tokens = policy
|
|
2141
|
+
.split(';')
|
|
2142
|
+
.map((t) => t.trim())
|
|
2143
|
+
.filter(Boolean);
|
|
2144
|
+
for (const token of tokens) {
|
|
2145
|
+
const spaceIndex = token.indexOf(' ');
|
|
2146
|
+
if (spaceIndex === -1) {
|
|
2147
|
+
const key = token;
|
|
2148
|
+
if (key === 'upgrade-insecure-requests' || key === 'block-all-mixed-content') {
|
|
2149
|
+
directives[key] = true;
|
|
2150
|
+
}
|
|
2151
|
+
else {
|
|
2152
|
+
directives[key] = [];
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
else {
|
|
2156
|
+
const key = token.substring(0, spaceIndex);
|
|
2157
|
+
const val = token
|
|
2158
|
+
.substring(spaceIndex + 1)
|
|
2159
|
+
.split(/\s+/)
|
|
2160
|
+
.filter(Boolean);
|
|
2161
|
+
directives[key] = val;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
return directives;
|
|
2165
|
+
}
|
|
2166
|
+
/**
|
|
2167
|
+
* Fluent builder for creating Content Security Policy (CSP) directives.
|
|
2168
|
+
*/
|
|
2169
|
+
class CspPolicyBuilder {
|
|
2170
|
+
directives = {};
|
|
2171
|
+
defaultSrc(values) {
|
|
2172
|
+
this.directives['default-src'] = Array.isArray(values) ? values : [values];
|
|
2173
|
+
return this;
|
|
2174
|
+
}
|
|
2175
|
+
scriptSrc(values) {
|
|
2176
|
+
this.directives['script-src'] = Array.isArray(values) ? values : [values];
|
|
2177
|
+
return this;
|
|
2178
|
+
}
|
|
2179
|
+
styleSrc(values) {
|
|
2180
|
+
this.directives['style-src'] = Array.isArray(values) ? values : [values];
|
|
2181
|
+
return this;
|
|
2182
|
+
}
|
|
2183
|
+
imgSrc(values) {
|
|
2184
|
+
this.directives['img-src'] = Array.isArray(values) ? values : [values];
|
|
2185
|
+
return this;
|
|
2186
|
+
}
|
|
2187
|
+
connectSrc(values) {
|
|
2188
|
+
this.directives['connect-src'] = Array.isArray(values) ? values : [values];
|
|
2189
|
+
return this;
|
|
2190
|
+
}
|
|
2191
|
+
fontSrc(values) {
|
|
2192
|
+
this.directives['font-src'] = Array.isArray(values) ? values : [values];
|
|
2193
|
+
return this;
|
|
2194
|
+
}
|
|
2195
|
+
frameSrc(values) {
|
|
2196
|
+
this.directives['frame-src'] = Array.isArray(values) ? values : [values];
|
|
2197
|
+
return this;
|
|
2198
|
+
}
|
|
2199
|
+
objectSrc(values) {
|
|
2200
|
+
this.directives['object-src'] = Array.isArray(values) ? values : [values];
|
|
2201
|
+
return this;
|
|
2202
|
+
}
|
|
2203
|
+
mediaSrc(values) {
|
|
2204
|
+
this.directives['media-src'] = Array.isArray(values) ? values : [values];
|
|
2205
|
+
return this;
|
|
2206
|
+
}
|
|
2207
|
+
childSrc(values) {
|
|
2208
|
+
this.directives['child-src'] = Array.isArray(values) ? values : [values];
|
|
2209
|
+
return this;
|
|
2210
|
+
}
|
|
2211
|
+
workerSrc(values) {
|
|
2212
|
+
this.directives['worker-src'] = Array.isArray(values) ? values : [values];
|
|
2213
|
+
return this;
|
|
2214
|
+
}
|
|
2215
|
+
manifestSrc(values) {
|
|
2216
|
+
this.directives['manifest-src'] = Array.isArray(values) ? values : [values];
|
|
2217
|
+
return this;
|
|
2218
|
+
}
|
|
2219
|
+
baseUri(values) {
|
|
2220
|
+
this.directives['base-uri'] = Array.isArray(values) ? values : [values];
|
|
2221
|
+
return this;
|
|
2222
|
+
}
|
|
2223
|
+
formAction(values) {
|
|
2224
|
+
this.directives['form-action'] = Array.isArray(values) ? values : [values];
|
|
2225
|
+
return this;
|
|
2226
|
+
}
|
|
2227
|
+
frameAncestors(values) {
|
|
2228
|
+
this.directives['frame-ancestors'] = Array.isArray(values) ? values : [values];
|
|
2229
|
+
return this;
|
|
2230
|
+
}
|
|
2231
|
+
reportUri(values) {
|
|
2232
|
+
this.directives['report-uri'] = Array.isArray(values) ? values : [values];
|
|
2233
|
+
return this;
|
|
2234
|
+
}
|
|
2235
|
+
reportTo(values) {
|
|
2236
|
+
this.directives['report-to'] = Array.isArray(values) ? values : [values];
|
|
2237
|
+
return this;
|
|
2238
|
+
}
|
|
2239
|
+
sandbox(values) {
|
|
2240
|
+
this.directives['sandbox'] = Array.isArray(values) ? values : [values];
|
|
2241
|
+
return this;
|
|
2242
|
+
}
|
|
2243
|
+
upgradeInsecureRequests(value = true) {
|
|
2244
|
+
this.directives['upgrade-insecure-requests'] = value;
|
|
2245
|
+
return this;
|
|
2246
|
+
}
|
|
2247
|
+
blockAllMixedContent(value = true) {
|
|
2248
|
+
this.directives['block-all-mixed-content'] = value;
|
|
2249
|
+
return this;
|
|
2250
|
+
}
|
|
2251
|
+
set(directive, values) {
|
|
2252
|
+
if (typeof values === 'boolean') {
|
|
2253
|
+
this.directives[directive] = values;
|
|
2254
|
+
}
|
|
2255
|
+
else {
|
|
2256
|
+
this.directives[directive] = Array.isArray(values) ? values : [values];
|
|
2257
|
+
}
|
|
2258
|
+
return this;
|
|
2259
|
+
}
|
|
2260
|
+
build() {
|
|
2261
|
+
return { ...this.directives };
|
|
2262
|
+
}
|
|
2263
|
+
toString() {
|
|
2264
|
+
return serializeCsp(this.directives);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Service for dynamically applying and auditing Content Security Policies (CSP).
|
|
2269
|
+
*/
|
|
2270
|
+
class CspService {
|
|
2271
|
+
meta = inject(Meta);
|
|
2272
|
+
/**
|
|
2273
|
+
* Applies the CSP policy dynamically by adding or updating a <meta http-equiv="Content-Security-Policy"> tag.
|
|
2274
|
+
*/
|
|
2275
|
+
applyPolicy(policy) {
|
|
2276
|
+
const content = typeof policy === 'string' ? policy : serializeCsp(policy);
|
|
2277
|
+
this.meta.updateTag({
|
|
2278
|
+
'http-equiv': 'Content-Security-Policy',
|
|
2279
|
+
content,
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
/**
|
|
2283
|
+
* Performs static analysis on a CSP policy and reports potential vulnerabilities or errors.
|
|
2284
|
+
*/
|
|
2285
|
+
auditPolicy(policy) {
|
|
2286
|
+
const directives = typeof policy === 'string' ? parseCsp(policy) : policy;
|
|
2287
|
+
const issues = [];
|
|
2288
|
+
// 1. Missing default-src
|
|
2289
|
+
const defaultSrc = directives['default-src'];
|
|
2290
|
+
if (!defaultSrc || defaultSrc.length === 0) {
|
|
2291
|
+
issues.push({
|
|
2292
|
+
severity: 'error',
|
|
2293
|
+
directive: 'default-src',
|
|
2294
|
+
message: "CSP policy is missing 'default-src' directive. It is recommended to set 'default-src \\'none\\'' and selectively override.",
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
// 2. Wildcards in sensitive directives
|
|
2298
|
+
const sensitiveDirectives = [
|
|
2299
|
+
'default-src',
|
|
2300
|
+
'script-src',
|
|
2301
|
+
'style-src',
|
|
2302
|
+
'connect-src',
|
|
2303
|
+
'img-src',
|
|
2304
|
+
'font-src',
|
|
2305
|
+
'object-src',
|
|
2306
|
+
'frame-src',
|
|
2307
|
+
];
|
|
2308
|
+
for (const dir of sensitiveDirectives) {
|
|
2309
|
+
const val = directives[dir];
|
|
2310
|
+
if (Array.isArray(val) && val.includes('*')) {
|
|
2311
|
+
if (['default-src', 'script-src', 'connect-src'].includes(dir)) {
|
|
2312
|
+
issues.push({
|
|
2313
|
+
severity: 'error',
|
|
2314
|
+
directive: dir,
|
|
2315
|
+
message: `Directive '${dir}' contains the wildcard '*'. This allows loading or executing resources from any external origin.`,
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
else {
|
|
2319
|
+
issues.push({
|
|
2320
|
+
severity: 'warning',
|
|
2321
|
+
directive: dir,
|
|
2322
|
+
message: `Directive '${dir}' contains the wildcard '*'. Consider restricting this to trusted origins.`,
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
// 3. 'unsafe-inline' without safety fallback (nonces or hashes or strict-dynamic)
|
|
2328
|
+
const inlineSensitiveDirectives = ['default-src', 'script-src', 'style-src'];
|
|
2329
|
+
for (const dir of inlineSensitiveDirectives) {
|
|
2330
|
+
const val = directives[dir];
|
|
2331
|
+
if (Array.isArray(val) && val.includes("'unsafe-inline'")) {
|
|
2332
|
+
const hasNonce = val.some((v) => v.startsWith("'nonce-"));
|
|
2333
|
+
const hasHash = val.some((v) => v.startsWith("'sha256-") || v.startsWith("'sha384-") || v.startsWith("'sha512-"));
|
|
2334
|
+
const hasStrictDynamic = dir === 'script-src' && val.includes("'strict-dynamic'");
|
|
2335
|
+
if (!hasNonce && !hasHash && !hasStrictDynamic) {
|
|
2336
|
+
issues.push({
|
|
2337
|
+
severity: 'error',
|
|
2338
|
+
directive: dir,
|
|
2339
|
+
message: `Directive '${dir}' allows 'unsafe-inline' without nonces, hashes, or 'strict-dynamic'. This renders your application vulnerable to Cross-Site Scripting (XSS).`,
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
// 4. Directives not supported in meta tags
|
|
2345
|
+
const unsupportedMetaDirectives = ['frame-ancestors', 'sandbox', 'report-uri', 'report-to'];
|
|
2346
|
+
for (const dir of unsupportedMetaDirectives) {
|
|
2347
|
+
if (directives[dir] !== undefined) {
|
|
2348
|
+
issues.push({
|
|
2349
|
+
severity: 'warning',
|
|
2350
|
+
directive: dir,
|
|
2351
|
+
message: `Directive '${dir}' is defined in the policy, but it is not supported or ignored when delivered via HTML <meta> tags.`,
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
// 5. Always add the general dynamic meta warning/info
|
|
2356
|
+
issues.push({
|
|
2357
|
+
severity: 'info',
|
|
2358
|
+
message: 'Policies applied dynamically via <meta http-equiv="Content-Security-Policy"> only affect resources loaded after the tag is inserted.',
|
|
2359
|
+
});
|
|
2360
|
+
const isValid = !issues.some((issue) => issue.severity === 'error');
|
|
2361
|
+
return {
|
|
2362
|
+
isValid,
|
|
2363
|
+
issues,
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: CspService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2367
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: CspService, providedIn: 'root' });
|
|
2368
|
+
}
|
|
2369
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: CspService, decorators: [{
|
|
2370
|
+
type: Injectable,
|
|
2371
|
+
args: [{
|
|
2372
|
+
providedIn: 'root',
|
|
2373
|
+
}]
|
|
2374
|
+
}] });
|
|
2375
|
+
|
|
2067
2376
|
/**
|
|
2068
2377
|
* Generated bundle index. Do not edit.
|
|
2069
2378
|
*/
|
|
2070
2379
|
|
|
2071
|
-
export { CSRF_CONFIG, ClipboardUnsupportedError, CsrfService, DEFAULT_ALLOWED_ATTRIBUTES, DEFAULT_ALLOWED_TAGS, HIBP_CONFIG, HibpService, InputSanitizerService, InvalidJwtError, JwtService, PasswordStrengthService, RATE_LIMITER_CONFIG, RateLimitExceededError, RateLimiterService, RegexAnalyzerService, RegexSecurityBuilder, RegexSecurityService, RegexWorkerPoolService, SANITIZER_CONFIG, SECURE_STORAGE_CONFIG, SecureMessageService, SecureStorageService, SensitiveClipboardService, SessionIdleService, WebCryptoService, assessPasswordStrength, containsScriptInjection, containsSqlInjectionHints, defaultSecurityConfig, isHtmlSafe, isUrlSafe, provideCsrf, provideHibp, provideInputSanitizer, provideJwt, providePasswordStrength, provideRateLimiter, provideRegexSecurity, provideSecureMessage, provideSecureStorage, provideSecurity, provideSensitiveClipboard, provideSessionIdle, provideWebCrypto, sanitizeHtmlString, sanitizeUrlString, withCsrfHeader };
|
|
2380
|
+
export { CSRF_CONFIG, ClipboardUnsupportedError, CspPolicyBuilder, CspService, CsrfService, DEFAULT_ALLOWED_ATTRIBUTES, DEFAULT_ALLOWED_TAGS, HIBP_CONFIG, HibpService, InputSanitizerService, InvalidJwtError, JwtService, PasswordStrengthService, RATE_LIMITER_CONFIG, RateLimitExceededError, RateLimiterService, RegexAnalyzerService, RegexSecurityBuilder, RegexSecurityService, RegexWorkerPoolService, SANITIZER_CONFIG, SECURE_STORAGE_CONFIG, SecureMessageService, SecureStorageService, SensitiveClipboardService, SessionIdleService, WebCryptoService, assessPasswordStrength, containsScriptInjection, containsSqlInjectionHints, defaultSecurityConfig, isHtmlSafe, isUrlSafe, parseCsp, provideCsrf, provideHibp, provideInputSanitizer, provideJwt, providePasswordStrength, provideRateLimiter, provideRegexSecurity, provideSecureMessage, provideSecureStorage, provideSecurity, provideSensitiveClipboard, provideSessionIdle, provideWebCrypto, sanitizeHtmlString, sanitizeUrlString, serializeCsp, withCsrfHeader };
|
package/package.json
CHANGED
|
@@ -276,7 +276,9 @@ declare class InputSanitizerService {
|
|
|
276
276
|
isSupported(): boolean;
|
|
277
277
|
/**
|
|
278
278
|
* Parses and sanitizes an HTML string, keeping only allowed tags and attributes.
|
|
279
|
-
*
|
|
279
|
+
* Leverages the native browser Sanitizer API (e.g. Element.prototype.setHTML) if available
|
|
280
|
+
* for high-performance execution, falling back to a custom DOMParser implementation on
|
|
281
|
+
* unsupported environments (such as older browsers or SSR).
|
|
280
282
|
*
|
|
281
283
|
* @throws {Error} When called in a non-browser environment.
|
|
282
284
|
*/
|
|
@@ -876,5 +878,91 @@ declare class RegexWorkerPoolService implements OnDestroy {
|
|
|
876
878
|
static ɵprov: i0.ɵɵInjectableDeclaration<RegexWorkerPoolService>;
|
|
877
879
|
}
|
|
878
880
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
+
interface CspDirectives {
|
|
882
|
+
'default-src'?: string[];
|
|
883
|
+
'script-src'?: string[];
|
|
884
|
+
'style-src'?: string[];
|
|
885
|
+
'img-src'?: string[];
|
|
886
|
+
'connect-src'?: string[];
|
|
887
|
+
'font-src'?: string[];
|
|
888
|
+
'frame-src'?: string[];
|
|
889
|
+
'object-src'?: string[];
|
|
890
|
+
'media-src'?: string[];
|
|
891
|
+
'child-src'?: string[];
|
|
892
|
+
'worker-src'?: string[];
|
|
893
|
+
'manifest-src'?: string[];
|
|
894
|
+
'base-uri'?: string[];
|
|
895
|
+
'form-action'?: string[];
|
|
896
|
+
'frame-ancestors'?: string[];
|
|
897
|
+
'report-uri'?: string[];
|
|
898
|
+
'report-to'?: string[];
|
|
899
|
+
sandbox?: string[];
|
|
900
|
+
'upgrade-insecure-requests'?: boolean | string[];
|
|
901
|
+
'block-all-mixed-content'?: boolean | string[];
|
|
902
|
+
[key: string]: string[] | boolean | undefined;
|
|
903
|
+
}
|
|
904
|
+
interface CspAuditIssue {
|
|
905
|
+
severity: 'error' | 'warning' | 'info';
|
|
906
|
+
directive?: string;
|
|
907
|
+
message: string;
|
|
908
|
+
}
|
|
909
|
+
interface CspAuditReport {
|
|
910
|
+
isValid: boolean;
|
|
911
|
+
issues: CspAuditIssue[];
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Serializes a CspDirectives object into a standard CSP policy string.
|
|
915
|
+
*/
|
|
916
|
+
declare function serializeCsp(directives: CspDirectives): string;
|
|
917
|
+
/**
|
|
918
|
+
* Parses a CSP policy string into a CspDirectives object.
|
|
919
|
+
*/
|
|
920
|
+
declare function parseCsp(policy: string): CspDirectives;
|
|
921
|
+
/**
|
|
922
|
+
* Fluent builder for creating Content Security Policy (CSP) directives.
|
|
923
|
+
*/
|
|
924
|
+
declare class CspPolicyBuilder {
|
|
925
|
+
private directives;
|
|
926
|
+
defaultSrc(values: string[] | string): this;
|
|
927
|
+
scriptSrc(values: string[] | string): this;
|
|
928
|
+
styleSrc(values: string[] | string): this;
|
|
929
|
+
imgSrc(values: string[] | string): this;
|
|
930
|
+
connectSrc(values: string[] | string): this;
|
|
931
|
+
fontSrc(values: string[] | string): this;
|
|
932
|
+
frameSrc(values: string[] | string): this;
|
|
933
|
+
objectSrc(values: string[] | string): this;
|
|
934
|
+
mediaSrc(values: string[] | string): this;
|
|
935
|
+
childSrc(values: string[] | string): this;
|
|
936
|
+
workerSrc(values: string[] | string): this;
|
|
937
|
+
manifestSrc(values: string[] | string): this;
|
|
938
|
+
baseUri(values: string[] | string): this;
|
|
939
|
+
formAction(values: string[] | string): this;
|
|
940
|
+
frameAncestors(values: string[] | string): this;
|
|
941
|
+
reportUri(values: string[] | string): this;
|
|
942
|
+
reportTo(values: string[] | string): this;
|
|
943
|
+
sandbox(values: string[] | string): this;
|
|
944
|
+
upgradeInsecureRequests(value?: boolean): this;
|
|
945
|
+
blockAllMixedContent(value?: boolean): this;
|
|
946
|
+
set(directive: string, values: string[] | string | boolean): this;
|
|
947
|
+
build(): CspDirectives;
|
|
948
|
+
toString(): string;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Service for dynamically applying and auditing Content Security Policies (CSP).
|
|
952
|
+
*/
|
|
953
|
+
declare class CspService {
|
|
954
|
+
private readonly meta;
|
|
955
|
+
/**
|
|
956
|
+
* Applies the CSP policy dynamically by adding or updating a <meta http-equiv="Content-Security-Policy"> tag.
|
|
957
|
+
*/
|
|
958
|
+
applyPolicy(policy: string | CspDirectives): void;
|
|
959
|
+
/**
|
|
960
|
+
* Performs static analysis on a CSP policy and reports potential vulnerabilities or errors.
|
|
961
|
+
*/
|
|
962
|
+
auditPolicy(policy: string | CspDirectives): CspAuditReport;
|
|
963
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CspService, never>;
|
|
964
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CspService>;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
export { CSRF_CONFIG, ClipboardUnsupportedError, CspPolicyBuilder, CspService, CsrfService, DEFAULT_ALLOWED_ATTRIBUTES, DEFAULT_ALLOWED_TAGS, HIBP_CONFIG, HibpService, InputSanitizerService, InvalidJwtError, JwtService, PasswordStrengthService, RATE_LIMITER_CONFIG, RateLimitExceededError, RateLimiterService, RegexAnalyzerService, RegexSecurityBuilder, RegexSecurityService, RegexWorkerPoolService, SANITIZER_CONFIG, SECURE_STORAGE_CONFIG, SecureMessageService, SecureStorageService, SensitiveClipboardService, SessionIdleService, WebCryptoService, assessPasswordStrength, containsScriptInjection, containsSqlInjectionHints, defaultSecurityConfig, isHtmlSafe, isUrlSafe, parseCsp, provideCsrf, provideHibp, provideInputSanitizer, provideJwt, providePasswordStrength, provideRateLimiter, provideRegexSecurity, provideSecureMessage, provideSecureStorage, provideSecurity, provideSensitiveClipboard, provideSessionIdle, provideWebCrypto, sanitizeHtmlString, sanitizeUrlString, serializeCsp, withCsrfHeader };
|
|
968
|
+
export type { AesEncryptResult, AesKeyLength, CopyStatus, CspAuditIssue, CspAuditReport, CspDirectives, CsrfConfig, CsrfHeaderOptions, CsrfStorageTarget, HashAlgorithm, HibpConfig, HibpResult, HmacAlgorithm, HtmlSanitizerOptions, HttpMethod, JwtStandardClaims, PasswordAssessment, PasswordLabel, PasswordScore, PasswordStrengthResult, RateLimitPolicy, RateLimiterConfig, RegexBuilderOptions, RegexSecurityConfig, RegexSecurityResult, RegexTestResult, SanitizerConfig, SecureMessage, SecureMessageConfig, SecureStorageConfig, SecurityConfig, SensitiveCopyOptions, SessionIdleConfig, StorageTarget };
|