• Icon: Epic Epic
    • Resolution: Unresolved
    • Icon: Minor Minor
    • _unsorted
    • None
    • CSP compatibility for Jenkins plugins

      Full details on the approach: https://docs.google.com/document/d/1hr_Kaf0fVWBACibpHbSYsk4RoqcHD3cBrqXxuTtWKVM (public)


      Without entering too much into details, to achieve a good CSP protection, we need to create a whitelist of URL that are approved (could be same-origin) for static content (CSS / JavaScript) or/and a list of whitelisted / authorized content. Adding a content (using its hash) to the whitelist has the drawback to add weight on every response.

      The advantage of that set of headers is to prevent a large number of XSS threats. The mechanism will prevent the execution of unauthorized scripts and styles.

      To achieve this migration with as little pain as possible, here are the proposed steps:
      1) Moving inline scripts / styles to their own file or equivalent
      2) Put in a place sort of a reporting / monitoring tooling inside Jenkins to know when a rule is broken
      3) Once we are sufficiently confident we have covered all the cases, enforce the rules.

      The points 1 and 2 will already help in prevent "direct" XSS where variables are injected in the code directly. That will also clean up a bit the different (and weird) ways to inject variables into JavaScript / CSS.


      Compatibility for plugins
      https://docs.google.com/spreadsheets/d/1Jr5FpkAN-FjTd0D_VLz00Ab5iXNiCK03fUs2JR2omXQ

      Documentation on jenkins.io about how to find and adjust code
      https://www.jenkins.io/doc/developer/security/csp/

          [JENKINS-60865] CSP compatibility for Jenkins plugins

          Ian Williams added a comment - - edited

          I'm not sure this is the best place to ask, but it seems to be a question worth considering in context  ...

          There are a number of plugins which do not work properly as a result of the (now) default CSP restrictions.

          Some of this is documented in the wiki (Maven integration, javadoc, HTML Publisher). Others are referenced in the Comments (Gatling, OWASP, PHP Code Coverage). I know of others from personal experience (Robot Framework) and there are plenty of questions on StackOverflow

          I don't know that I can trust much of the guidance or generalize from it. The most common piece of advice is simply to turn off the security, which is very risky. Some experimentation shows a more granular relaxation of rules also results in a functional plugin.

          What would really help though is the requirement in the plug-in documentation that, IF the default CSP settings breaks the plug-in functionality, the plug-in provider must provide the appropriate documentation of which minimal settings must be relaxed to restore functionality.

           

          Ian Williams added a comment - - edited I'm not sure this is the best place to ask, but it seems to be a question worth considering in context  ... There are a number of plugins which do not work properly as a result of the (now) default CSP restrictions. Some of this is documented in the wiki (Maven integration, javadoc, HTML Publisher) . Others are referenced in the Comments (Gatling, OWASP, PHP Code Coverage). I know of others from personal experience (Robot Framework) and there are plenty of questions on StackOverflow I don't know that I can trust much of the guidance or generalize from it. The most common piece of advice is simply to turn off the security, which is very risky. Some experimentation shows a more granular relaxation of rules also results in a functional plugin. What would really help though is the requirement in the plug-in documentation that, IF the default CSP settings breaks the plug-in functionality, the plug-in provider must provide the appropriate documentation of which minimal settings must be relaxed to restore functionality.  

          Wadeck Follonier added a comment - - edited

          ianw The CSP restrictions you are talking about are only for the DirectoryBrowser stuff and it was "solved" by the introduction of the ResourceDomain feature.

          References:

          The most common piece of advice is simply to turn off the security

          No longer the case with the resource domain (and IIRC there is an admin monitor activated if you disabled the CSP, proposing to move to second domain)

          This Epic is more about "CSP everywhere". But I really understand your fear here, especially with all the plugin (1600+) we have to care about. It's the reason of the step 2 in the proposal. In a proprietary software, the step 2 would not have been required.

          Wadeck Follonier added a comment - - edited ianw The CSP restrictions you are talking about are only for the DirectoryBrowser stuff and it was "solved" by the introduction of the ResourceDomain feature. References: https://wiki.jenkins.io/display/JENKINS/Configuring+Content+Security+Policy "Alternatives" https://issues.jenkins-ci.org/browse/JENKINS-41891 and its PR: https://github.com/jenkinsci/jenkins/pull/4239 The most common piece of advice is simply to turn off the security No longer the case with the resource domain (and IIRC there is an admin monitor activated if you disabled the CSP, proposing to move to second domain) This Epic is more about "CSP everywhere". But I really understand your fear here, especially with all the plugin (1600+) we have to care about. It's the reason of the step 2 in the proposal. In a proprietary software, the step 2 would not have been required.

          Ian Williams added a comment -

          wfollonier

          Thank you for the prompt response. We are just about to start planning to upgrade 2.204 LTS, so was not aware /JENKINS-41891 was Fixed. We will review this impact.

          I look forward to how the reporting tool will work and what kind of communication there will be back to plug-in providers so as to rehabilitate their plug-ins or provide better user guidance and action where necessary if issues remain.

          Ian Williams added a comment - wfollonier Thank you for the prompt response. We are just about to start planning to upgrade 2.204 LTS, so was not aware /JENKINS-41891 was Fixed. We will review this impact. I look forward to how the reporting tool will work and what kind of communication there will be back to plug-in providers so as to rehabilitate their plug-ins or provide better user guidance and action where necessary if issues remain.

          I look forward to how the reporting tool will work and what kind of communication there will be back to plug-in providers so as to rehabilitate their plug-ins or provide better user guidance and action where necessary if issues remain.

          It will be a public effort so any feedback will be more than appreciated Not only from a maintainer PoV but also for the admin/user's one

          Wadeck Follonier added a comment - I look forward to how the reporting tool will work and what kind of communication there will be back to plug-in providers so as to rehabilitate their plug-ins or provide better user guidance and action where necessary if issues remain. It will be a public effort so any feedback will be more than appreciated Not only from a maintainer PoV but also for the admin/user's one

          Daniel Beck added a comment -

          https://github.com/jenkinsci/csp-plugin/ is a plugin to help identify problematic scripts. Not yet hosted on update sites as Jenkins would be very broken if it's configure to enforce, and it's pretty spammy in general.

          Daniel Beck added a comment - https://github.com/jenkinsci/csp-plugin/ is a plugin to help identify problematic scripts. Not yet hosted on update sites as Jenkins would be very broken if it's configure to enforce, and it's pretty spammy in general.

          The Content-Security-Policy is going to block unsafe-eval, right? Android Emulator and any other plugins that nowadays use checkUrl without checkDependsOn will then have to be fixed.

          Kalle Niemitalo added a comment - The Content-Security-Policy is going to block unsafe-eval , right? Android Emulator and any other plugins that nowadays use checkUrl without checkDependsOn will then have to be fixed.

          Daniel Beck added a comment -

          Known problem and it's in very widespread use  Ideally we'll figure out a good replacement for new development (I would be surprised if checkDependsOn covers everything), as well as a way to transform existing values into something safe to send to a browser. Contributions welcome.

          Daniel Beck added a comment - Known problem and it's in very widespread use  Ideally we'll figure out a good replacement for new development (I would be surprised if checkDependsOn covers everything), as well as a way to transform existing values into something safe to send to a browser. Contributions welcome.

          Daniel Beck added a comment -

          Android Emulator and any other plugins that nowadays use checkUrl without checkDependsOn will then have to be fixed.

          FTR https://www.jenkins.io/doc/developer/security/csp/#legacy-javascript-checkurl-validation – I expect most fields should be fairly straightforward to adapt.

          Daniel Beck added a comment - Android Emulator and any other plugins that nowadays use checkUrl without checkDependsOn will then have to be fixed. FTR https://www.jenkins.io/doc/developer/security/csp/#legacy-javascript-checkurl-validation – I expect most fields should be fairly straightforward to adapt.

            shlomo_dahan Shlomo
            wfollonier Wadeck Follonier
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: