Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-74579

[probely-security] Extract inline script block in com/probely/plugin/ProbelyScanBuilder/config.jelly

      Problem

      == Inline Script Block
      Line: 22
      ----
      <script>
      /*<![CDATA[*/
      (function () {
          let count = 0;
          const limit = 10;
          function getParentElmByTag(node, selector1, selector2) {
              if (!node) {
                  return null;
              }
              const nodeSelector1 = node.closest(selector1);
              const nodeSelector2 = node.closest(selector2);
              if (nodeSelector1) {
                  return nodeSelector1;
              } else if (nodeSelector2) {
                  return nodeSelector2;
              }
              return null;
          }
          function runCode() {
              const waitForScan = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.waitForScan"]');
              const failThreshold = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] select[name="_.failThreshold"]');
              const stopIfFailed = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.stopIfFailed"]');
              const failThresholdContainer = getParentElmByTag(failThreshold, 'tr', 'div.tr');
              const stopIfFailedContainer = getParentElmByTag(stopIfFailed, 'tr', 'div.tr');
              function onChangeHandler() {
                  if (!waitForScan.checked) {
                      stopIfFailedContainer.style.visibility = 'hidden';
                      failThresholdContainer.style.visibility = 'hidden';
                  } else {
                      stopIfFailedContainer.style.visibility = 'visible';
                      failThresholdContainer.style.visibility = 'visible';
                  }
              }
              if (waitForScan !== null && failThresholdContainer !== null && stopIfFailedContainer !== null) {
                  onChangeHandler();
                  waitForScan.addEventListener('change', () => {
                      onChangeHandler();
                  });
                  return;
              }
              if (count < limit) {
                  setTimeout(function() {
                      runCode();
                  }, 500);
              }
              count++;
          }
          runCode();
      })();
      /*]]>*/
           </script>
      ----
      

      Solution

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks

          [JENKINS-74579] [probely-security] Extract inline script block in com/probely/plugin/ProbelyScanBuilder/config.jelly

          Basil Crow created issue -
          Basil Crow made changes -
          Assignee Original: Joao Poupino [ poupas ]
          Basil Crow made changes -
          Description Original: h4. Problems

          {noformat}
          == Inline Script Block
          Line: 22
          ----
          <script>
          /*<![CDATA[*/
          (function () {
              let count = 0;
              const limit = 10;
              function getParentElmByTag(node, selector1, selector2) {
                  if (!node) {
                      return null;
                  }
                  const nodeSelector1 = node.closest(selector1);
                  const nodeSelector2 = node.closest(selector2);
                  if (nodeSelector1) {
                      return nodeSelector1;
                  } else if (nodeSelector2) {
                      return nodeSelector2;
                  }
                  return null;
              }
              function runCode() {
                  const waitForScan = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.waitForScan"]');
                  const failThreshold = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] select[name="_.failThreshold"]');
                  const stopIfFailed = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.stopIfFailed"]');
                  const failThresholdContainer = getParentElmByTag(failThreshold, 'tr', 'div.tr');
                  const stopIfFailedContainer = getParentElmByTag(stopIfFailed, 'tr', 'div.tr');
                  function onChangeHandler() {
                      if (!waitForScan.checked) {
                          stopIfFailedContainer.style.visibility = 'hidden';
                          failThresholdContainer.style.visibility = 'hidden';
                      } else {
                          stopIfFailedContainer.style.visibility = 'visible';
                          failThresholdContainer.style.visibility = 'visible';
                      }
                  }
                  if (waitForScan !== null && failThresholdContainer !== null && stopIfFailedContainer !== null) {
                      onChangeHandler();
                      waitForScan.addEventListener('change', () => {
                          onChangeHandler();
                      });
                      return;
                  }
                  if (count < limit) {
                      setTimeout(function() {
                          runCode();
                      }, 500);
                  }
                  count++;
              }
              runCode();
          })();
          /*]]>*/
               </script>
          ----

          == Inline Script Block
          Line: 22
          ----
          <script>
          /*<![CDATA[*/
          (function () {
              let count = 0;
              const limit = 10;
              function getParentElmByTag(node, selector1, selector2) {
                  if (!node) {
                      return null;
                  }
                  const nodeSelector1 = node.closest(selector1);
                  const nodeSelector2 = node.closest(selector2);
                  if (nodeSelector1) {
                      return nodeSelector1;
                  } else if (nodeSelector2) {
                      return nodeSelector2;
                  }
                  return null;
              }
              function runCode() {
                  const waitForScan = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.waitForScan"]');
                  const failThreshold = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] select[name="_.failThreshold"]');
                  const stopIfFailed = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.stopIfFailed"]');
                  const failThresholdContainer = getParentElmByTag(failThreshold, 'tr', 'div.tr');
                  const stopIfFailedContainer = getParentElmByTag(stopIfFailed, 'tr', 'div.tr');
                  function onChangeHandler() {
                      if (!waitForScan.checked) {
                          stopIfFailedContainer.style.visibility = 'hidden';
                          failThresholdContainer.style.visibility = 'hidden';
                      } else {
                          stopIfFailedContainer.style.visibility = 'visible';
                          failThresholdContainer.style.visibility = 'visible';
                      }
                  }
                  if (waitForScan !== null && failThresholdContainer !== null && stopIfFailedContainer !== null) {
                      onChangeHandler();
                      waitForScan.addEventListener('change', () => {
                          onChangeHandler();
                      });
                      return;
                  }
                  if (count < limit) {
                      setTimeout(function() {
                          runCode();
                      }, 500);
                  }
                  count++;
              }
              runCode();
          })();
          /*]]>*/
               </script>
          ----
          {noformat}

          h4. Solution

          [https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks]
          New: h4. Problem

          {noformat}
          == Inline Script Block
          Line: 22
          ----
          <script>
          /*<![CDATA[*/
          (function () {
              let count = 0;
              const limit = 10;
              function getParentElmByTag(node, selector1, selector2) {
                  if (!node) {
                      return null;
                  }
                  const nodeSelector1 = node.closest(selector1);
                  const nodeSelector2 = node.closest(selector2);
                  if (nodeSelector1) {
                      return nodeSelector1;
                  } else if (nodeSelector2) {
                      return nodeSelector2;
                  }
                  return null;
              }
              function runCode() {
                  const waitForScan = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.waitForScan"]');
                  const failThreshold = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] select[name="_.failThreshold"]');
                  const stopIfFailed = document.querySelector('div[descriptorid="com.probely.plugin.ProbelyScanBuilder"] input[name="_.stopIfFailed"]');
                  const failThresholdContainer = getParentElmByTag(failThreshold, 'tr', 'div.tr');
                  const stopIfFailedContainer = getParentElmByTag(stopIfFailed, 'tr', 'div.tr');
                  function onChangeHandler() {
                      if (!waitForScan.checked) {
                          stopIfFailedContainer.style.visibility = 'hidden';
                          failThresholdContainer.style.visibility = 'hidden';
                      } else {
                          stopIfFailedContainer.style.visibility = 'visible';
                          failThresholdContainer.style.visibility = 'visible';
                      }
                  }
                  if (waitForScan !== null && failThresholdContainer !== null && stopIfFailedContainer !== null) {
                      onChangeHandler();
                      waitForScan.addEventListener('change', () => {
                          onChangeHandler();
                      });
                      return;
                  }
                  if (count < limit) {
                      setTimeout(function() {
                          runCode();
                      }, 500);
                  }
                  count++;
              }
              runCode();
          })();
          /*]]>*/
               </script>
          ----
          {noformat}

          h4. Solution

          [https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks]
          Summary Original: [probely-security] Extract inline script blocks in com/probely/plugin/ProbelyScanBuilder/config.jelly New: [probely-security] Extract inline script block in com/probely/plugin/ProbelyScanBuilder/config.jelly

            Unassigned Unassigned
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: