soiz1 commited on
Commit
28e4ace
·
verified ·
1 Parent(s): 9c464e9

Update src/extensions/jg_iframe/index.js

Browse files
Files changed (1) hide show
  1. src/extensions/jg_iframe/index.js +6 -60
src/extensions/jg_iframe/index.js CHANGED
@@ -1,7 +1,6 @@
1
  const formatMessage = require('format-message');
2
  const BlockType = require('../../extension-support/block-type');
3
  const ArgumentType = require('../../extension-support/argument-type');
4
- const ProjectPermissionManager = require('../../util/project-permissions');
5
  const Color = require('../../util/color');
6
  const Cast = require('../../util/cast');
7
 
@@ -20,24 +19,6 @@ const EffectOptions = {
20
  ]
21
  };
22
 
23
- const urlToReportUrl = (url) => {
24
- let urlObject;
25
- try {
26
- urlObject = new URL(url);
27
- } catch {
28
- // we cant really throw an error in this state since it halts any blocks
29
- // or return '' since thatll just confuse the api likely
30
- // so just use example.com
31
- return 'example.com';
32
- }
33
- // use host name
34
- return urlObject.hostname;
35
- };
36
-
37
- // to avoid taking 1290 years for each url set
38
- // we save the ones that we already checked
39
- const safeOriginUrls = {};
40
-
41
  /**
42
  * uhhhhhhhhhh
43
  * @param {Array} array the array
@@ -52,26 +33,6 @@ const ArrayToValue = (array, value) => {
52
  return object;
53
  };
54
 
55
- const isUrlRatedSafe = (url) => {
56
- return new Promise((resolve) => {
57
- const saveUrl = urlToReportUrl(url);
58
- if (safeOriginUrls.hasOwnProperty(saveUrl)) {
59
- return resolve(safeOriginUrls[saveUrl]);
60
- }
61
-
62
- fetch(`https://pm-bapi.vercel.app/api/safeurl?url=${saveUrl}`).then(res => {
63
- if (!res.ok) {
64
- resolve(true);
65
- return;
66
- }
67
- res.json().then(status => {
68
- safeOriginUrls[saveUrl] = status.safe;
69
- resolve(status.safe);
70
- }).catch(() => resolve(true));
71
- }).catch(() => resolve(true));
72
- })
73
- }
74
-
75
  /**
76
  * Class for IFRAME blocks
77
  * @constructor
@@ -480,10 +441,7 @@ class JgIframeBlocks {
480
  }
481
  // permissions
482
  async IsWebsiteAllowed(url) {
483
- if (ProjectPermissionManager.IsDataUrl(url)) return true;
484
- if (!ProjectPermissionManager.IsUrlSafe(url)) return false;
485
- const safe = await isUrlRatedSafe(url);
486
- return safe;
487
  }
488
 
489
  // utilities
@@ -628,28 +586,16 @@ class JgIframeBlocks {
628
  }
629
  setIframeUrl(args) {
630
  if (!this.GetIFrameState()) return; // iframe doesnt exist, stop
631
- let usingProxy = false;
632
  let checkingUrl = args.URL;
633
- if (Cast.toString(args.URL).startsWith("proxy://")) {
634
- // use the penguin mod proxy but still say we are on proxy:// since its what the user input
635
- // replace proxy:// with https:// though since we are still using the https protocol
636
- usingProxy = true;
637
- checkingUrl = Cast.toString(args.URL).replace("proxy://", "https://");
638
- }
639
  if (Cast.toString(args.URL) === 'about:blank') {
640
  this.createdIframe.src = "about:blank";
641
  this.displayWebsiteUrl = "about:blank";
642
  return;
643
  }
644
- this.IsWebsiteAllowed(checkingUrl).then(safe => {
645
- if (!safe) { // website isnt in the permitted sites list?
646
- this.createdIframe.src = "about:blank";
647
- this.displayWebsiteUrl = args.URL;
648
- return;
649
- }
650
- this.createdIframe.src = (usingProxy ? `https://detaproxy-1-s1965152.deta.app/?url=${Cast.toString(args.URL).replace("proxy://", "https://")}` : args.URL);
651
- // tell the user we are on proxy:// still since it looks nicer than the disgusting deta url
652
- this.displayWebsiteUrl = (usingProxy ? `${Cast.toString(this.createdIframe.src).replace("https://detaproxy-1-s1965152.deta.app/?url=https://", "proxy://")}` : this.createdIframe.src);
653
  });
654
  }
655
  setIframePosLeft(args) {
@@ -824,4 +770,4 @@ class JgIframeBlocks {
824
  }
825
  }
826
 
827
- module.exports = JgIframeBlocks;
 
1
  const formatMessage = require('format-message');
2
  const BlockType = require('../../extension-support/block-type');
3
  const ArgumentType = require('../../extension-support/argument-type');
 
4
  const Color = require('../../util/color');
5
  const Cast = require('../../util/cast');
6
 
 
19
  ]
20
  };
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  /**
23
  * uhhhhhhhhhh
24
  * @param {Array} array the array
 
33
  return object;
34
  };
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  /**
37
  * Class for IFRAME blocks
38
  * @constructor
 
441
  }
442
  // permissions
443
  async IsWebsiteAllowed(url) {
444
+ return await this.runtime.vm.securityManager.canEmbed(url);
 
 
 
445
  }
446
 
447
  // utilities
 
586
  }
587
  setIframeUrl(args) {
588
  if (!this.GetIFrameState()) return; // iframe doesnt exist, stop
589
+
590
  let checkingUrl = args.URL;
 
 
 
 
 
 
591
  if (Cast.toString(args.URL) === 'about:blank') {
592
  this.createdIframe.src = "about:blank";
593
  this.displayWebsiteUrl = "about:blank";
594
  return;
595
  }
596
+ this.IsWebsiteAllowed(checkingUrl).then(() => {
597
+ this.createdIframe.src = args.URL;
598
+ this.displayWebsiteUrl = this.createdIframe.src;
 
 
 
 
 
 
599
  });
600
  }
601
  setIframePosLeft(args) {
 
770
  }
771
  }
772
 
773
+ module.exports = JgIframeBlocks;