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

Ugly form validation for sidebar link of folder

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • sidebar-link-plugin
    • None
    • Sidebar Link plugin 2.2.2
      Folders plugin 6.815.v0dd5a_cb_40e0e
      Jenkins 2.401.1

      To reproduce

      Create a job with type Folder and name "linktest".
      In the configuration of the folder, expand "Sidebar Links", click "Add Link", and enter the following information:

      Click "Apply".

      Expected results

      An error message below the "Link URL" field explains that the "file" scheme is not allowed.

      Note: This works correctly on the "System" configuration page (/manage/configure), but not in folder configuration.

      Actual results

      A message pops up:

      Error

      A problem occurred while processing the request.

      Logging ID=6f1a8ac1-509b-423a-8388-cf1fb89b7b64

      and the Jenkins log shows the stack trace of the error:

      kesäk. 02, 2023 4:44:31 IP. WARNING hudson.init.impl.InstallUncaughtExceptionHandler handleException
      
      Caught unhandled exception with ID 6f1a8ac1-509b-423a-8388-cf1fb89b7b64
      ERROR: URI scheme "file" is not allowed. Allowed schemes: news,ftps,ftp,rtsp,svn,xmpp,nntp,feed,mms,telnet,http,mailto,tel,https,irc,fax,gopher
      	at hudson.util.FormValidation._errorWithMarkup(FormValidation.java:273)
      	at hudson.util.FormValidation.errorWithMarkup(FormValidation.java:259)
      	at hudson.util.FormValidation.error(FormValidation.java:150)
      	at hudson.plugins.sidebar_link.LinkProtection.verifyUrl(LinkProtection.java:94)
      	at hudson.plugins.sidebar_link.LinkAction.<init>(LinkAction.java:64)
      Caused: java.lang.IllegalArgumentException
      	at hudson.plugins.sidebar_link.LinkAction.<init>(LinkAction.java:66)
      	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
      	at org.kohsuke.stapler.RequestImpl.invokeConstructor(RequestImpl.java:602)
      	at org.kohsuke.stapler.RequestImpl.instantiate(RequestImpl.java:881)
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:766)
      Caused: java.lang.IllegalArgumentException: Failed to instantiate class hudson.plugins.sidebar_link.LinkAction from {"urlName":"file://localhost/","displayName":"Local Files","iconFileName":"folder"}
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:769)
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:805)
      	at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:549)
      	at org.kohsuke.stapler.RequestImpl.instantiate(RequestImpl.java:875)
      Caused: java.lang.IllegalArgumentException: Failed to convert the links parameter of the constructor public hudson.plugins.sidebar_link.FolderLinks(java.util.List)
      	at org.kohsuke.stapler.RequestImpl.instantiate(RequestImpl.java:877)
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:766)
      Caused: java.lang.IllegalArgumentException: Failed to instantiate class hudson.plugins.sidebar_link.FolderLinks from {"links":{"urlName":"file://localhost/","displayName":"Local Files","iconFileName":"folder"}}
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:769)
      	at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:549)
      	at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:544)
      	at hudson.model.Descriptor.bindJSON(Descriptor.java:622)
      	at hudson.model.Descriptor.newInstance(Descriptor.java:592)
      Caused: java.lang.LinkageError: Failed to instantiate class hudson.plugins.sidebar_link.FolderLinks from {"links":{"urlName":"file://localhost/","displayName":"Local Files","iconFileName":"folder"}}
      	at hudson.model.Descriptor.newInstance(Descriptor.java:595)
      	at com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor.newInstance(AbstractFolderPropertyDescriptor.java:55)
      	at com.cloudbees.hudson.plugins.folder.FolderPropertyDescriptor.newInstance(FolderPropertyDescriptor.java:40)
      	at com.cloudbees.hudson.plugins.folder.FolderPropertyDescriptor.newInstance(FolderPropertyDescriptor.java:36)
      	at hudson.util.DescribableList.rebuild(DescribableList.java:179)
      	at com.cloudbees.hudson.plugins.folder.AbstractFolder.doConfigSubmit(AbstractFolder.java:1354)
      	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:710)
      	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:397)
      	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:409)
      	at org.kohsuke.stapler.interceptor.RequirePOST$Processor.invoke(RequirePOST.java:78)
      	at org.kohsuke.stapler.PreInvokeInterceptedFunction.invoke(PreInvokeInterceptedFunction.java:26)
      	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:207)
      	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:140)
      	at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:558)
      	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:59)
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:770)
      Caused: javax.servlet.ServletException
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:818)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
      	at org.kohsuke.stapler.MetaClass$4.doDispatch(MetaClass.java:289)
      	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:59)
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:770)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:698)
      	at org.kohsuke.stapler.Stapler.service(Stapler.java:248)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
      

      (I omit the rest of the stack trace because it seems uninteresting.)

          [JENKINS-71391] Ugly form validation for sidebar link of folder

          src/main/java/hudson/plugins/sidebar_link/SidebarLinkPlugin.java defines a method

              @Restricted(NoExternalUse.class)
              public FormValidation doCheckLinkUrl(@QueryParameter String value) {
                  return LinkProtection.verifyUrl(value);
              }
          

          but I don't understand how that is wired up with src/main/resources/hudson/plugins/sidebar_link/links.jelly

                      <f:entry title="${%Link URL}" help="/plugin/sidebar-link/help-url.html">
                          <f:textbox name="urlName" value="${link.unprotectedUrlName}" field="linkUrl"/>
                      </f:entry>
          

          and what would have to be done to make it work in FolderLinks as well.

          Kalle Niemitalo added a comment - src/main/java/hudson/plugins/sidebar_link/SidebarLinkPlugin.java defines a method @Restricted(NoExternalUse.class) public FormValidation doCheckLinkUrl(@QueryParameter String value) { return LinkProtection.verifyUrl(value); } but I don't understand how that is wired up with src/main/resources/hudson/plugins/sidebar_link/links.jelly <f:entry title= "${%Link URL}" help= "/plugin/sidebar-link/help-url.html" > <f:textbox name= "urlName" value= "${link.unprotectedUrlName}" field= "linkUrl" /> </f:entry> and what would have to be done to make it work in FolderLinks as well.

          Markus Winter added a comment - - edited

          The plugin needs to set the checkUrl attribute on all 3 inputs in the links.jelly to point to the corresponding methods in the SidebarLinkPlugin class

          What happens now with folder and I guess also for project and node links is that Jenkins tries to save them and then a LinkAction gets created which again validates the url which throws the exception

          When you configure it globally it is in the context of the SidebarLinkPlugin class and the check method can be autimatically called.

          Alternatively the descriptors of folder, project and node would to also need to define corresponding check methods.

          Markus Winter added a comment - - edited The plugin needs to set the checkUrl attribute on all 3 inputs in the links.jelly to point to the corresponding methods in the SidebarLinkPlugin class What happens now with folder and I guess also for project and node links is that Jenkins tries to save them and then a LinkAction gets created which again validates the url which throws the exception When you configure it globally it is in the context of the SidebarLinkPlugin class and the check method can be autimatically called. Alternatively the descriptors of folder, project and node would to also need to define corresponding check methods.

          I cannot reproduce the error. File scheme is not valid and this is reported properly:

          Damian Szczepanik added a comment - I cannot reproduce the error. File scheme is not valid and this is reported properly:

          Check the most recent version - should be fine

          Damian Szczepanik added a comment - Check the most recent version - should be fine

          Kalle Niemitalo added a comment - - edited

          With Sidebar Link 2.2.3, I now get a form validation message below the "Link URL" text field, as expected:

          Uri scheme "file" is not allowed. Allowed schemes: news,ftps,ftp,rtsp,svn,xmpp,nntp,feed,mms,telnet,http,mailto,tel,https,irc,fax,gopher

          If I ignore the message and click "Apply", then I get "A problem occurred while processing the request" anyway. It would be nice if that message pinpointed the field that has the validation error. However, because the Sidebar Link settings in the System configuration don't work any better in that respect, that seems better handled as a separate issue. I thus verify the fix in 2.2.3.

          Kalle Niemitalo added a comment - - edited With Sidebar Link 2.2.3, I now get a form validation message below the "Link URL" text field, as expected: Uri scheme "file" is not allowed. Allowed schemes: news,ftps,ftp,rtsp,svn,xmpp,nntp,feed,mms,telnet,http,mailto,tel,https,irc,fax,gopher If I ignore the message and click "Apply", then I get "A problem occurred while processing the request" anyway. It would be nice if that message pinpointed the field that has the validation error. However, because the Sidebar Link settings in the System configuration don't work any better in that respect, that seems better handled as a separate issue. I thus verify the fix in 2.2.3.

            dszczepanik Damian Szczepanik
            kon Kalle Niemitalo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: