snyk 1.766.0 → 1.767.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.
@@ -672,7 +672,7 @@ exports.computeCustomRulesBundleChecksum = computeCustomRulesBundleChecksum;
672
672
  "use strict";
673
673
 
674
674
  Object.defineProperty(exports, "__esModule", ({ value: true }));
675
- exports.FailedToExecuteCustomRulesError = exports.FailedToPullCustomBundleError = exports.pullIaCCustomRules = exports.isValidURL = exports.removeFileContent = exports.test = void 0;
675
+ exports.FailedToExecuteCustomRulesError = exports.FailedToPullCustomBundleError = exports.pullIaCCustomRules = exports.removeFileContent = exports.test = void 0;
676
676
  const detect_1 = __webpack_require__(45318);
677
677
  const types_1 = __webpack_require__(42258);
678
678
  const analytics_1 = __webpack_require__(22716);
@@ -688,6 +688,7 @@ const errors_1 = __webpack_require__(55191);
688
688
  const error_utils_1 = __webpack_require__(23872);
689
689
  const oci_pull_1 = __webpack_require__(5029);
690
690
  const unsupported_entitlement_error_1 = __webpack_require__(78673);
691
+ const url_utils_1 = __webpack_require__(80256);
691
692
  // this method executes the local processing engine and then formats the results to adapt with the CLI output.
692
693
  // this flow is the default GA flow for IAC scanning.
693
694
  async function test(pathToScan, options) {
@@ -759,17 +760,6 @@ function removeFileContent({ filePath, fileType, failureReason, projectType, })
759
760
  };
760
761
  }
761
762
  exports.removeFileContent = removeFileContent;
762
- function isValidURL(str) {
763
- let url;
764
- try {
765
- url = new URL(str);
766
- }
767
- catch (e) {
768
- return false;
769
- }
770
- return url.protocol === 'http:' || url.protocol === 'https:';
771
- }
772
- exports.isValidURL = isValidURL;
773
763
  /**
774
764
  * Checks if the OCI registry URL has been provided.
775
765
  */
@@ -790,9 +780,6 @@ function checkOCIRegistryURLExistsInSettings(iacOrgSettings) {
790
780
  */
791
781
  function getOCIRegistryURLComponentsFromSettings(iacOrgSettings) {
792
782
  const settingsOCIRegistryURL = iacOrgSettings.customRules.ociRegistryURL;
793
- if (!isValidURL(settingsOCIRegistryURL)) {
794
- throw new oci_pull_1.InvalidRemoteRegistryURLError();
795
- }
796
783
  return {
797
784
  ...oci_pull_1.extractOCIRegistryURLComponents(settingsOCIRegistryURL),
798
785
  tag: iacOrgSettings.customRules.ociRegistryTag || 'latest',
@@ -803,7 +790,7 @@ function getOCIRegistryURLComponentsFromSettings(iacOrgSettings) {
803
790
  */
804
791
  function getOCIRegistryURLComponentsFromEnv() {
805
792
  const envOCIRegistryURL = user_config_1.config.get('oci-registry-url');
806
- if (!isValidURL(envOCIRegistryURL)) {
793
+ if (!url_utils_1.isValidUrl(envOCIRegistryURL)) {
807
794
  throw new oci_pull_1.InvalidRemoteRegistryURLError();
808
795
  }
809
796
  return oci_pull_1.extractOCIRegistryURLComponents(envOCIRegistryURL);
@@ -1216,15 +1203,28 @@ const debug = Debug('iac-oci-pull');
1216
1203
  exports.CUSTOM_RULES_TARBALL = 'custom-bundle.tar.gz';
1217
1204
  function extractOCIRegistryURLComponents(OCIRegistryURL) {
1218
1205
  try {
1219
- const url = new URL(OCIRegistryURL);
1220
- const registryBase = url.hostname;
1221
- // with or without a path, there will at least be a / in the pathname
1222
- const repoWithTag = url.pathname.substring(1);
1206
+ const urlWithoutProtocol = OCIRegistryURL.includes('://')
1207
+ ? OCIRegistryURL.split('://')[1]
1208
+ : OCIRegistryURL;
1209
+ const firstSlashIdx = urlWithoutProtocol.indexOf('/');
1210
+ if (firstSlashIdx === -1) {
1211
+ throw new InvalidRemoteRegistryURLError(OCIRegistryURL);
1212
+ }
1213
+ const [registryHost, repoWithTag] = [
1214
+ urlWithoutProtocol.substring(0, firstSlashIdx),
1215
+ urlWithoutProtocol.substring(firstSlashIdx + 1),
1216
+ ];
1217
+ if (!registryHost || !repoWithTag) {
1218
+ throw new InvalidRemoteRegistryURLError(OCIRegistryURL);
1219
+ }
1223
1220
  const [repo, tag = 'latest'] = repoWithTag.split(':');
1224
- return { registryBase, repo, tag };
1221
+ if (!repo) {
1222
+ throw new InvalidRemoteRegistryURLError(OCIRegistryURL);
1223
+ }
1224
+ return { registryBase: registryHost, repo, tag };
1225
1225
  }
1226
1226
  catch (_a) {
1227
- throw new InvalidRemoteRegistryURLError();
1227
+ throw new InvalidRemoteRegistryURLError(OCIRegistryURL);
1228
1228
  }
1229
1229
  }
1230
1230
  exports.extractOCIRegistryURLComponents = extractOCIRegistryURLComponents;
@@ -1278,12 +1278,11 @@ class InvalidManifestSchemaVersionError extends errors_1.CustomError {
1278
1278
  }
1279
1279
  exports.InvalidManifestSchemaVersionError = InvalidManifestSchemaVersionError;
1280
1280
  class InvalidRemoteRegistryURLError extends errors_1.CustomError {
1281
- constructor(message) {
1282
- super(message || 'Invalid URL for Remote Registry');
1281
+ constructor(url) {
1282
+ super('Invalid URL for Remote Registry');
1283
1283
  this.code = types_1.IaCErrorCodes.InvalidRemoteRegistryURLError;
1284
1284
  this.strCode = error_utils_1.getErrorStringCode(this.code);
1285
- this.userMessage =
1286
- 'The Remote Registry URL is invalid, or does not include a http/https protocol. Please check it again.';
1285
+ this.userMessage = `The provided remote registry URL${url ? `: "${url}"` : ''} is invalid. Please check it again.`;
1287
1286
  }
1288
1287
  }
1289
1288
  exports.InvalidRemoteRegistryURLError = InvalidRemoteRegistryURLError;
@@ -1821,6 +1820,25 @@ class FailedToFormatResults extends errors_1.CustomError {
1821
1820
  exports.FailedToFormatResults = FailedToFormatResults;
1822
1821
 
1823
1822
 
1823
+ /***/ }),
1824
+
1825
+ /***/ 80256:
1826
+ /***/ ((__unused_webpack_module, exports) => {
1827
+
1828
+ "use strict";
1829
+
1830
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1831
+ exports.isValidUrl = void 0;
1832
+ const URL_REGEX = /^((?:https?:\/\/)?[^./]+(?:\.[^./]+)+(?:\/.*)?)$/;
1833
+ /**
1834
+ * Checks if the provided URL string is valid.
1835
+ */
1836
+ function isValidUrl(urlStr) {
1837
+ return URL_REGEX.test(urlStr);
1838
+ }
1839
+ exports.isValidUrl = isValidUrl;
1840
+
1841
+
1824
1842
  /***/ }),
1825
1843
 
1826
1844
  /***/ 43156: