@forge/csp 0.0.0-experimental-7c72fec → 0.0.0-experimental-f85f9b1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,84 @@
1
1
  # @forge/csp
2
2
 
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 907ce6c: Add navigate-to CSP directive
8
+
9
+ ## 2.1.1-next.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 907ce6c: Add navigate-to CSP directive
14
+
15
+ ## 2.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - eeee3d3: Added ws://localhost to CSP
20
+
21
+ ## 2.1.0-next.0
22
+
23
+ ### Minor Changes
24
+
25
+ - eeee3d3f: Added ws://localhost to CSP
26
+
27
+ ## 2.0.1
28
+
29
+ ### Patch Changes
30
+
31
+ - 2a60561: Allow Forge Content Security Policy to load stylesheets from unpkg.com to enable an interim theme mounting solution for Atlassian Design System: Design Tokens
32
+
33
+ ## 2.0.1-next.0
34
+
35
+ ### Patch Changes
36
+
37
+ - 2a605619: Allow Forge Content Security Policy to load stylesheets from unpkg.com to enable an interim theme mounting solution for Atlassian Design System: Design Tokens
38
+
39
+ ## 2.0.0
40
+
41
+ ### Major Changes
42
+
43
+ - 3c0ac54: Move egress related services out of @forge/csp into new @forge/egress package
44
+
45
+ ## 2.0.0-next.0
46
+
47
+ ### Major Changes
48
+
49
+ - 3c0ac54: Move egress related services out of @forge/csp into new @forge/egress package
50
+
51
+ ## 1.11.0
52
+
53
+ ### Minor Changes
54
+
55
+ - 671a6a63: Skip generating hashes for inline scripts if unsafe-inline is provided
56
+
57
+ ## 1.11.0-next.0
58
+
59
+ ### Minor Changes
60
+
61
+ - 671a6a6: Skip generating hashes for inline scripts if unsafe-inline is provided
62
+
63
+ ## 1.10.0
64
+
65
+ ### Minor Changes
66
+
67
+ - e95919f: Added blob csp support for script content permissions with manifest validation
68
+ - 56164fe: Add allow-pointer-lock to iframe sandbox
69
+
70
+ ## 1.10.0-next.1
71
+
72
+ ### Minor Changes
73
+
74
+ - e95919f: Added blob csp support for script content permissions with manifest validation
75
+
76
+ ## 1.10.0-next.0
77
+
78
+ ### Minor Changes
79
+
80
+ - 56164fe: Add allow-pointer-lock to iframe sandbox
81
+
3
82
  ## 1.9.0
4
83
 
5
84
  ### Minor Changes
@@ -4,7 +4,8 @@ export declare class CSPInjectionService {
4
4
  private getCSPReportUri;
5
5
  private getForgeGlobalCSP;
6
6
  private getExistingCSPDetails;
7
+ private getConnectSrc;
7
8
  private getFrameAncestors;
8
- getInjectableCSP: (existingCSPDetails: CSPDetails, env: LambdaEnvironment, tunnelCSPReporterUri?: string | undefined) => string[];
9
+ getInjectableCSP: (existingCSPDetails: CSPDetails, microsEnv: LambdaEnvironment, tunnelCSPReporterUri?: string) => string[];
9
10
  }
10
11
  //# sourceMappingURL=csp-injection-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"csp-injection-service.d.ts","sourceRoot":"","sources":["../../src/csp/csp-injection-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAmB,MAAM,UAAU,CAAC;AAUvD,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,iBAAiB;IAalB,gBAAgB,uBACD,UAAU,OACzB,iBAAiB,gDAErB,MAAM,EAAE,CA4CT;CACH"}
1
+ {"version":3,"file":"csp-injection-service.d.ts","sourceRoot":"","sources":["../../src/csp/csp-injection-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAmB,MAAM,UAAU,CAAC;AAUvD,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,iBAAiB;IAiBlB,gBAAgB,uBACD,UAAU,aACnB,iBAAiB,yBACL,MAAM,KAC5B,MAAM,EAAE,CAqDT;CACH"}
@@ -10,10 +10,10 @@ const atlassianImageHosts = {
10
10
  const gravatarUrl = 'https://secure.gravatar.com';
11
11
  class CSPInjectionService {
12
12
  constructor() {
13
- this.getInjectableCSP = (existingCSPDetails, env, tunnelCSPReporterUri) => {
14
- const reportUri = tunnelCSPReporterUri || this.getCSPReportUri(env);
13
+ this.getInjectableCSP = (existingCSPDetails, microsEnv, tunnelCSPReporterUri) => {
14
+ const reportUri = tunnelCSPReporterUri || this.getCSPReportUri(microsEnv);
15
15
  const defaultSrc = `'self'`;
16
- const frameAncestors = ["'self'", ...this.getFrameAncestors(env)].join(' ');
16
+ const frameAncestors = ["'self'", ...this.getFrameAncestors(microsEnv)].join(' ');
17
17
  const frameSrc = ["'self'", ...this.getExistingCSPDetails(types_1.ExternalCspType.FRAME_SRC, existingCSPDetails)].join(' ');
18
18
  const fontSrc = ["'self'", ...this.getExistingCSPDetails(types_1.ExternalCspType.FONT_SRC, existingCSPDetails)].join(' ');
19
19
  const imgSrc = [
@@ -21,7 +21,7 @@ class CSPInjectionService {
21
21
  'data:',
22
22
  'blob:',
23
23
  gravatarUrl,
24
- ...atlassianImageHosts[env],
24
+ ...atlassianImageHosts[microsEnv],
25
25
  ...this.getExistingCSPDetails(types_1.ExternalCspType.IMG_SRC, existingCSPDetails)
26
26
  ].join(' ');
27
27
  const mediaSrc = [
@@ -30,13 +30,18 @@ class CSPInjectionService {
30
30
  'blob:',
31
31
  ...this.getExistingCSPDetails(types_1.ExternalCspType.MEDIA_SRC, existingCSPDetails)
32
32
  ].join(' ');
33
- const connectSrc = ["'self'", ...this.getExistingCSPDetails(types_1.ExternalCspType.CONNECT_SRC, existingCSPDetails)].join(' ');
33
+ const connectSrc = [
34
+ "'self'",
35
+ ...this.getConnectSrc(!!tunnelCSPReporterUri),
36
+ ...this.getExistingCSPDetails(types_1.ExternalCspType.CONNECT_SRC, existingCSPDetails)
37
+ ].join(' ');
34
38
  const scriptSrc = [
35
39
  "'self'",
36
- this.getForgeGlobalCSP(env),
40
+ this.getForgeGlobalCSP(microsEnv),
37
41
  ...this.getExistingCSPDetails(types_1.ExternalCspType.SCRIPT_SRC, existingCSPDetails)
38
42
  ].join(' ');
39
43
  const styleSrc = ["'self'", ...this.getExistingCSPDetails(types_1.ExternalCspType.STYLE_SRC, existingCSPDetails)].join(' ');
44
+ const navigateTo = ["'self'"];
40
45
  return [
41
46
  `default-src ${defaultSrc}`,
42
47
  `frame-ancestors ${frameAncestors}`,
@@ -46,38 +51,43 @@ class CSPInjectionService {
46
51
  `media-src ${mediaSrc}`,
47
52
  `connect-src ${connectSrc}`,
48
53
  `script-src ${scriptSrc}`,
49
- `style-src ${styleSrc}`,
54
+ `navigate-to ${navigateTo}`,
55
+ `style-src ${styleSrc} https://unpkg.com/@atlaskit/tokens@0.10.30/css/atlassian-light.css https://unpkg.com/@atlaskit/tokens@0.10.30/css/atlassian-dark.css`,
50
56
  `form-action 'self'`,
51
- `sandbox allow-downloads allow-forms allow-modals allow-same-origin allow-scripts`,
57
+ `sandbox allow-downloads allow-forms allow-modals allow-pointer-lock allow-same-origin allow-scripts`,
52
58
  `report-uri ${reportUri}`
53
59
  ];
54
60
  };
55
61
  }
56
- getCSPReportUri(env, tunnelCSPReporterUri) {
57
- if (tunnelCSPReporterUri)
58
- return tunnelCSPReporterUri;
59
- if (env === 'prod')
60
- return 'https://web-security-reports.services.atlassian.com/csp-report/forge-cdn';
61
- return 'https://web-security-reports.stg.services.atlassian.com/csp-report/forge-cdn';
62
+ getCSPReportUri(microsEnv) {
63
+ if (microsEnv === 'dev' || microsEnv === 'stg')
64
+ return 'https://web-security-reports.stg.services.atlassian.com/csp-report/forge-cdn';
65
+ return 'https://web-security-reports.services.atlassian.com/csp-report/forge-cdn';
62
66
  }
63
- getForgeGlobalCSP(env) {
64
- return `https://forge.cdn.${env}.atlassian-dev.net`;
67
+ getForgeGlobalCSP(microsEnv) {
68
+ return `https://forge.cdn.${microsEnv}.atlassian-dev.net`;
65
69
  }
66
70
  getExistingCSPDetails(cspType, cspDetails) {
67
71
  var _a;
68
72
  return (_a = cspDetails[cspType]) !== null && _a !== void 0 ? _a : [];
69
73
  }
70
- getFrameAncestors(env) {
71
- if (env === 'prod')
72
- return ['*.atlassian.net', 'bitbucket.org', '*.jira.com', '*.atlassian.com'];
73
- return [
74
- '*.jira-dev.com',
75
- 'http://localhost:*',
76
- '*.devbucket.org',
77
- 'https://staging.bb-inf.net',
78
- 'https://integration.bb-inf.net',
79
- '*.atl-paas.net'
80
- ];
74
+ getConnectSrc(isTunnelling) {
75
+ if (isTunnelling)
76
+ return ['ws://localhost:*', 'http://localhost:*'];
77
+ return [];
78
+ }
79
+ getFrameAncestors(microsEnv) {
80
+ if (microsEnv === 'dev' || microsEnv === 'stg') {
81
+ return [
82
+ '*.jira-dev.com',
83
+ 'http://localhost:*',
84
+ '*.devbucket.org',
85
+ 'https://staging.bb-inf.net',
86
+ 'https://integration.bb-inf.net',
87
+ '*.atl-paas.net'
88
+ ];
89
+ }
90
+ return ['*.atlassian.net', 'bitbucket.org', '*.jira.com', '*.atlassian.com'];
81
91
  }
82
92
  }
83
93
  exports.CSPInjectionService = CSPInjectionService;
@@ -6,6 +6,11 @@ export declare class InvalidConnectSrc extends Error {
6
6
  }
7
7
  export declare class CSPProcessingService {
8
8
  private readonly logger;
9
+ private STYLE_SRC_ALLOWLIST;
10
+ private QUOTED_SCRIPT_SRC_ALLOWLIST;
11
+ private UNQUOTED_SCRIPT_SRC_ALLOWLIST;
12
+ private SCRIPT_SRC_ALLOWLIST;
13
+ private BASE_64_HASH_PATTERNS;
9
14
  constructor(logger: Pick<Logger, 'info'>);
10
15
  getCspDetails(body: DocumentBody, permissions: Permissions): CSPDetails;
11
16
  getInvalidCspPermissions(contentPermissions: ContentPermissions): string[];
@@ -16,6 +21,7 @@ export declare class CSPProcessingService {
16
21
  private extractUniqueHashes;
17
22
  private getInlineScriptHashes;
18
23
  private hashScript;
24
+ private formatScriptSrc;
19
25
  private isValidUserScriptSrc;
20
26
  private isValidUserStyleSrc;
21
27
  private isSafeCsp;
@@ -1 +1 @@
1
- {"version":3,"file":"csp-processing-service.d.ts","sourceRoot":"","sources":["../../src/csp/csp-processing-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,iBAAiB,CAAC;AAK1D,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,YAAY,EAAuB,MAAM,UAAU,CAAC;AAa7F,qBAAa,iBAAkB,SAAQ,KAAK;;CAI3C;AAMD,qBAAa,oBAAoB;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IAElD,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,GAAG,UAAU;IAkBvE,wBAAwB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,MAAM,EAAE;IASjF,OAAO,CAAC,sBAAsB;IAW9B,OAAO,CAAC,2BAA2B;IAgBnC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,oBAAoB;CAa7B"}
1
+ {"version":3,"file":"csp-processing-service.d.ts","sourceRoot":"","sources":["../../src/csp/csp-processing-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,iBAAiB,CAAC;AAK1D,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,YAAY,EAAuB,MAAM,UAAU,CAAC;AAE7F,qBAAa,iBAAkB,SAAQ,KAAK;;CAI3C;AAMD,qBAAa,oBAAoB;IAanB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAXnC,OAAO,CAAC,mBAAmB,CAAuB;IAElD,OAAO,CAAC,2BAA2B,CAAqD;IACxF,OAAO,CAAC,6BAA6B,CAAa;IAClD,OAAO,CAAC,oBAAoB,CAAgF;IAE5G,OAAO,CAAC,qBAAqB,CAI3B;gBAC2B,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IAElD,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,GAAG,UAAU;IAkBvE,wBAAwB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,MAAM,EAAE;IASjF,OAAO,CAAC,sBAAsB;IAW9B,OAAO,CAAC,2BAA2B;IAgBnC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,oBAAoB;CAa7B"}
@@ -5,13 +5,6 @@ const tslib_1 = require("tslib");
5
5
  const cheerio_1 = tslib_1.__importDefault(require("cheerio"));
6
6
  const content_security_policy_parser_1 = tslib_1.__importDefault(require("content-security-policy-parser"));
7
7
  const crypto_1 = tslib_1.__importDefault(require("crypto"));
8
- const STYLE_SRC_ALLOWLIST = [`'unsafe-inline'`];
9
- const SCRIPT_SRC_ALLOWLIST = [`'unsafe-inline'`, `'unsafe-eval'`, `'unsafe-hashes'`];
10
- const BASE_64_HASH_PATTERNS = [
11
- /^'sha256-[a-zA-Z0-9=+/]{44}'$/,
12
- /^'sha384-[a-zA-Z0-9=+/]{64}'$/,
13
- /^'sha512-[a-zA-Z0-9=+/]{88}'$/
14
- ];
15
8
  class InvalidConnectSrc extends Error {
16
9
  constructor() {
17
10
  super('fetch.client should be an array of strings');
@@ -21,6 +14,15 @@ exports.InvalidConnectSrc = InvalidConnectSrc;
21
14
  class CSPProcessingService {
22
15
  constructor(logger) {
23
16
  this.logger = logger;
17
+ this.STYLE_SRC_ALLOWLIST = [`'unsafe-inline'`];
18
+ this.QUOTED_SCRIPT_SRC_ALLOWLIST = ['unsafe-inline', 'unsafe-eval', 'unsafe-hashes'];
19
+ this.UNQUOTED_SCRIPT_SRC_ALLOWLIST = ['blob:'];
20
+ this.SCRIPT_SRC_ALLOWLIST = [...this.QUOTED_SCRIPT_SRC_ALLOWLIST, ...this.UNQUOTED_SCRIPT_SRC_ALLOWLIST];
21
+ this.BASE_64_HASH_PATTERNS = [
22
+ /^sha256-[a-zA-Z0-9=+/]{44}$/,
23
+ /^sha384-[a-zA-Z0-9=+/]{64}$/,
24
+ /^sha512-[a-zA-Z0-9=+/]{88}$/
25
+ ];
24
26
  }
25
27
  getCspDetails(body, permissions) {
26
28
  var _a, _b;
@@ -34,7 +36,7 @@ class CSPProcessingService {
34
36
  var _a, _b;
35
37
  const { styles, scripts } = contentPermissions;
36
38
  const invalidStyles = (_a = styles === null || styles === void 0 ? void 0 : styles.filter((styleSrc) => !this.isValidUserStyleSrc(`'${styleSrc}'`))) !== null && _a !== void 0 ? _a : [];
37
- const invalidScripts = (_b = scripts === null || scripts === void 0 ? void 0 : scripts.filter((scriptSrc) => !this.isValidUserScriptSrc(`'${scriptSrc}'`))) !== null && _b !== void 0 ? _b : [];
39
+ const invalidScripts = (_b = scripts === null || scripts === void 0 ? void 0 : scripts.filter((scriptSrc) => !this.isValidUserScriptSrc(scriptSrc))) !== null && _b !== void 0 ? _b : [];
38
40
  return [...invalidStyles, ...invalidScripts];
39
41
  }
40
42
  assertValidFetchClient(fetch) {
@@ -63,17 +65,16 @@ class CSPProcessingService {
63
65
  getStyleSrc($, userStyleSrc) {
64
66
  var _a, _b;
65
67
  const quotedUserStyleSrc = (_a = userStyleSrc === null || userStyleSrc === void 0 ? void 0 : userStyleSrc.map((x) => `'${x}'`)) !== null && _a !== void 0 ? _a : [];
66
- const deprecatedUserScriptSrc = (_b = this.getDeprecatedUserCsp($)['style-src']) !== null && _b !== void 0 ? _b : [];
67
- const uniqueStyleSrc = [...new Set([...deprecatedUserScriptSrc, ...quotedUserStyleSrc])];
68
+ const deprecatedUserStyleSrc = (_b = this.getDeprecatedUserCsp($)['style-src']) !== null && _b !== void 0 ? _b : [];
69
+ const uniqueStyleSrc = [...new Set([...deprecatedUserStyleSrc, ...quotedUserStyleSrc])];
68
70
  return uniqueStyleSrc.filter((x) => this.isValidUserStyleSrc(x));
69
71
  }
70
72
  getScriptSrc($, userScriptSrc) {
71
73
  var _a;
72
- const generatedScriptHashes = this.getInlineScriptHashes($);
73
- const quotedUserScriptSrc = (_a = userScriptSrc === null || userScriptSrc === void 0 ? void 0 : userScriptSrc.map((x) => `'${x}'`)) !== null && _a !== void 0 ? _a : [];
74
- const validUserScriptSrc = quotedUserScriptSrc.filter((x) => this.isValidUserScriptSrc(x));
74
+ const validUserScriptSrc = (_a = userScriptSrc === null || userScriptSrc === void 0 ? void 0 : userScriptSrc.filter((x) => this.isValidUserScriptSrc(x))) !== null && _a !== void 0 ? _a : [];
75
+ const generatedScriptHashes = validUserScriptSrc.includes('unsafe-inline') ? [] : this.getInlineScriptHashes($);
75
76
  const { scriptSrc, userScriptHashes } = this.extractUniqueHashes(validUserScriptSrc, generatedScriptHashes);
76
- return [...scriptSrc, ...generatedScriptHashes, ...userScriptHashes];
77
+ return [...scriptSrc, ...generatedScriptHashes, ...userScriptHashes].map((x) => this.formatScriptSrc(x));
77
78
  }
78
79
  extractUniqueHashes(userScriptSrc, existingScriptHashes) {
79
80
  var _a;
@@ -88,35 +89,40 @@ class CSPProcessingService {
88
89
  return { scriptSrc, userScriptHashes };
89
90
  }
90
91
  getInlineScriptHashes($) {
91
- const scriptHashes = $('script:not([src])')
92
+ return $('script:not([src])')
92
93
  .map((_index, script) => {
93
94
  const html = $(script).html();
94
- return html && `'sha256-${this.hashScript(html)}'`;
95
+ return html && `sha256-${this.hashScript(html)}`;
95
96
  })
96
97
  .get();
97
- return scriptHashes;
98
98
  }
99
99
  hashScript(content) {
100
100
  const sha256 = crypto_1.default.createHash('sha256');
101
101
  return sha256.update(content).digest('base64');
102
102
  }
103
+ formatScriptSrc(scriptSrc) {
104
+ if (this.UNQUOTED_SCRIPT_SRC_ALLOWLIST.includes(scriptSrc)) {
105
+ return scriptSrc;
106
+ }
107
+ return `'${scriptSrc}'`;
108
+ }
103
109
  isValidUserScriptSrc(scriptSrc) {
104
110
  if (!this.isSafeCsp(scriptSrc))
105
111
  return false;
106
- return this.isValidHash(scriptSrc) || SCRIPT_SRC_ALLOWLIST.includes(scriptSrc);
112
+ return this.isValidHash(scriptSrc) || this.SCRIPT_SRC_ALLOWLIST.includes(scriptSrc);
107
113
  }
108
114
  isValidUserStyleSrc(styleSrc) {
109
115
  if (!this.isSafeCsp(styleSrc)) {
110
116
  this.logger.info('discarding potentially-malicious CSP');
111
117
  return false;
112
118
  }
113
- return STYLE_SRC_ALLOWLIST.includes(styleSrc);
119
+ return this.STYLE_SRC_ALLOWLIST.includes(styleSrc);
114
120
  }
115
121
  isSafeCsp(cspString) {
116
- return /^[a-zA-Z0-9='"+\/ -]*$/.test(cspString);
122
+ return /^([a-zA-Z0-9='"+\/ -]|blob:)*$/.test(cspString);
117
123
  }
118
124
  isValidHash(cspString) {
119
- return BASE_64_HASH_PATTERNS.some((pattern) => pattern.test(cspString));
125
+ return this.BASE_64_HASH_PATTERNS.some((pattern) => pattern.test(cspString));
120
126
  }
121
127
  getDeprecatedUserCsp($) {
122
128
  const cspContent = $('meta[http-equiv="Content-Security-Policy"]').attr('content');
@@ -127,7 +133,7 @@ class CSPProcessingService {
127
133
  this.logger.info('discarding potentially-malicious CSP');
128
134
  return {};
129
135
  }
130
- return content_security_policy_parser_1.default(cspContent);
136
+ return (0, content_security_policy_parser_1.default)(cspContent);
131
137
  }
132
138
  }
133
139
  exports.CSPProcessingService = CSPProcessingService;
package/out/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './csp';
2
- export * from './egress';
3
2
  export * from './types';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC"}
package/out/index.js CHANGED
@@ -2,5 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./csp"), exports);
5
- tslib_1.__exportStar(require("./egress"), exports);
6
5
  tslib_1.__exportStar(require("./types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/csp",
3
- "version": "0.0.0-experimental-7c72fec",
3
+ "version": "0.0.0-experimental-f85f9b1",
4
4
  "description": "Contains the CSP configuration for Custom UI resources in Forge",
5
5
  "main": "out/index.js",
6
6
  "author": "Atlassian",
@@ -11,13 +11,12 @@
11
11
  "clean": "rm -rf ./out && rm -f tsconfig.tsbuildinfo"
12
12
  },
13
13
  "devDependencies": {
14
- "@forge/cli-shared": "^0.0.0-experimental-7c72fec",
15
- "@forge/manifest": "^0.0.0-experimental-7c72fec",
16
- "@types/jest": "^26.0.0"
14
+ "@forge/cli-shared": "0.0.0-experimental-f85f9b1",
15
+ "@forge/manifest": "0.0.0-experimental-f85f9b1",
16
+ "@types/jest": "^29.1.2"
17
17
  },
18
18
  "dependencies": {
19
19
  "cheerio": "^0.22.0",
20
- "content-security-policy-parser": "^0.3.0",
21
- "micromatch": "^4.0.2"
20
+ "content-security-policy-parser": "^0.3.0"
22
21
  }
23
22
  }
@@ -1,11 +0,0 @@
1
- export declare class EgressFilteringService {
2
- private readonly URLs;
3
- private readonly wildcardDomains;
4
- private readonly allowsEverything;
5
- constructor(allowList: string[]);
6
- private safeURL;
7
- isValidUrl(url: string): boolean;
8
- private domainCheck;
9
- private domainIsAllowed;
10
- }
11
- //# sourceMappingURL=egress-filtering-service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"egress-filtering-service.d.ts","sourceRoot":"","sources":["../../src/egress/egress-filtering-service.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;gBAE/B,SAAS,EAAE,MAAM,EAAE;IAY/B,OAAO,CAAC,OAAO;IAOR,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAQvC,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,eAAe;CAWxB"}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EgressFilteringService = void 0;
4
- const tslib_1 = require("tslib");
5
- const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
6
- const url_1 = require("url");
7
- class EgressFilteringService {
8
- constructor(allowList) {
9
- this.URLs = allowList
10
- .filter((domainOrURL) => !domainOrURL.startsWith('*'))
11
- .map((url) => this.safeURL(url));
12
- this.wildcardDomains = allowList
13
- .filter((domainOrURL) => domainOrURL !== '*')
14
- .map((url) => this.safeURL(url))
15
- .filter((url) => url.hostname.startsWith('*'));
16
- this.allowsEverything = allowList.includes('*');
17
- }
18
- safeURL(url, defaultProtocol = 'https://') {
19
- const protocolRegex = /^(.*:\/\/)/;
20
- return new url_1.URL(protocolRegex.test(url) ? url : `${defaultProtocol}${url}`);
21
- }
22
- isValidUrl(url) {
23
- if (this.allowsEverything) {
24
- return true;
25
- }
26
- return this.domainIsAllowed(this.safeURL(url));
27
- }
28
- domainCheck(domain, allowList) {
29
- const hostnameMatchedProtocol = allowList
30
- .filter((allowed) => allowed.protocol === domain.protocol)
31
- .map((url) => url.hostname);
32
- return (micromatch_1.default([domain.hostname], hostnameMatchedProtocol, {
33
- dot: true
34
- }).length > 0);
35
- }
36
- domainIsAllowed(domain) {
37
- if (this.domainCheck(domain, this.URLs)) {
38
- return true;
39
- }
40
- if (this.domainCheck(domain, this.wildcardDomains)) {
41
- return true;
42
- }
43
- return false;
44
- }
45
- }
46
- exports.EgressFilteringService = EgressFilteringService;
@@ -1,3 +0,0 @@
1
- export * from './egress-filtering-service';
2
- export * from './utils';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/egress/index.ts"],"names":[],"mappings":"AAEA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./egress-filtering-service"), exports);
5
- tslib_1.__exportStar(require("./utils"), exports);
@@ -1,3 +0,0 @@
1
- declare const sortAndGroupEgressPermissionsByDomain: (egressAddresses: string[]) => Array<string>;
2
- export { sortAndGroupEgressPermissionsByDomain };
3
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/egress/utils.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,qCAAqC,oBAAqB,MAAM,EAAE,KAAG,KAAK,CAAC,MAAM,CA2BtF,CAAC;AAEF,OAAO,EAAE,qCAAqC,EAAE,CAAC"}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortAndGroupEgressPermissionsByDomain = void 0;
4
- const tslib_1 = require("tslib");
5
- const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
6
- const url_1 = require("url");
7
- const sortAndGroupEgressPermissionsByDomain = (egressAddresses) => {
8
- const protocolRegex = /^(.*?:\/\/)/;
9
- const domainSet = new Set();
10
- const groupSet = new Set();
11
- const removeSet = new Set();
12
- if ((egressAddresses === null || egressAddresses === void 0 ? void 0 : egressAddresses.length) === 0) {
13
- return [];
14
- }
15
- egressAddresses.forEach((item) => {
16
- const itemWithProtocol = protocolRegex.test(item) ? item : `https://${item}`;
17
- const url = new url_1.URL(itemWithProtocol);
18
- if (url.hostname.startsWith('*')) {
19
- groupSet.add(url.hostname.substring(2));
20
- removeSet.add('!' + url.hostname);
21
- }
22
- else {
23
- domainSet.add(url.hostname);
24
- }
25
- });
26
- if (removeSet.size === 0) {
27
- return [...domainSet];
28
- }
29
- return [...new Set(micromatch_1.default([...domainSet], [...removeSet]).concat([...groupSet]))].sort();
30
- };
31
- exports.sortAndGroupEgressPermissionsByDomain = sortAndGroupEgressPermissionsByDomain;