- 
                Notifications
    
You must be signed in to change notification settings  - Fork 198
 
[JENKINS-63254][JENKINS-47101] Insecure Groovy String Interpolation Warnings #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
009bad3
              52f6f4b
              75c7406
              191f08e
              ccf9040
              5c53b94
              c5ef8ad
              1a7793d
              0829025
              18653c0
              5ba9b2a
              aeebf17
              02804b3
              20d781d
              b404458
              22c4ae3
              41984a6
              d4759b1
              4a98072
              8bdc019
              e975453
              d4765a4
              341972a
              ade619f
              79d255a
              0abb665
              7a5d0c7
              506d5b3
              93b018b
              065b129
              4903d4e
              cc5b3b0
              8517f12
              f12f226
              9a31bce
              6e8b5eb
              eaa4c90
              70c4c22
              8a799dc
              1afab59
              dbe7d8f
              902ab29
              6a39c5c
              ec29d4b
              97b1535
              b34e5fd
              b0d183b
              b846c44
              4f9997d
              8506214
              e6284e9
              ef157e9
              00d220b
              a8df396
              7c8022b
              a890c43
              36050b4
              163e7cb
              3740ed1
              a20db3d
              b14f8cf
              d489f73
              11b12ba
              bd0dfd2
              86cf9f3
              a24ffe0
              cd43425
              ac2ec02
              41e50e6
              3e54d36
              b52438d
              49695e0
              7d8672c
              611326c
              96c2f30
              7811148
              f7798af
              40eb64a
              bc8d268
              e173261
              4524d26
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -25,10 +25,14 @@ | |
| 
     | 
||
| import hudson.model.Run; | ||
| import jenkins.model.RunAction2; | ||
| import org.jenkinsci.plugins.structs.describable.DescribableModel; | ||
| import org.jenkinsci.plugins.structs.describable.DescribableParameter; | ||
| import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable; | ||
| import org.jenkinsci.plugins.workflow.actions.ArgumentsAction; | ||
| import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; | ||
| import org.jenkinsci.plugins.workflow.graph.FlowNode; | ||
| import org.jenkinsci.plugins.workflow.graph.StepNode; | ||
| import org.jenkinsci.plugins.workflow.steps.StepDescriptor; | ||
| import org.kohsuke.accmod.Restricted; | ||
| import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
| import org.kohsuke.stapler.export.Exported; | ||
| 
          
            
          
           | 
    @@ -117,32 +121,48 @@ public static class InterpolatedWarnings { | |
| @Exported | ||
| public String getStepSignature() { | ||
| Map<String, Object> stepArguments; | ||
| FlowNode node; | ||
| try { | ||
| stepArguments = getStepArguments(run, nodeId); | ||
| node = getFlowNode(run, nodeId); | ||
| ArgumentsAction argumentsAction = node.getPersistentAction(ArgumentsAction.class); | ||
| if (argumentsAction == null) { | ||
| throw new IllegalStateException("null arguments action"); | ||
| } | ||
| stepArguments = argumentsAction.getArguments(); | ||
| } catch (IllegalStateException e) { | ||
| return "Unable to construct " + stepName + ": " + e.getMessage(); | ||
| } | ||
| 
     | 
||
| if (node instanceof StepNode) { | ||
| StepDescriptor descriptor = ((StepNode)node).getDescriptor(); | ||
| if (descriptor != null && descriptor.isMetaStep()) { | ||
| DescribableParameter p = DescribableModel.of(descriptor.clazz).getFirstRequiredParameter(); | ||
| if (p != null) { | ||
| Object arg = ArgumentsAction.getResolvedArguments(node).get(p.getName()); | ||
| if (arg instanceof UninstantiatedDescribable) { | ||
| return argumentToString(arg); | ||
| } else { | ||
| return stepName + "(" + argumentToString(arg) + ")"; | ||
                
       | 
||
| } | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| return stepArguments.entrySet().stream() | ||
| .map(InterpolatedSecretsAction::argumentToString) | ||
| .collect(Collectors.joining(", ", stepName + "(", ")")); | ||
| } | ||
| 
     | 
||
| @Nonnull | ||
| private Map<String, Object> getStepArguments(Run run, String nodeId) throws IllegalStateException { | ||
| private FlowNode getFlowNode(Run run, String nodeId) { | ||
| String failReason; | ||
| if (run instanceof FlowExecutionOwner.Executable) { | ||
| try { | ||
| FlowExecutionOwner owner = ((FlowExecutionOwner.Executable) run).asFlowExecutionOwner(); | ||
| if (owner != null) { | ||
| FlowNode node = owner.get().getNode(nodeId); | ||
| if (node != null) { | ||
| ArgumentsAction argumentsAction = node.getPersistentAction(ArgumentsAction.class); | ||
| if (argumentsAction != null) { | ||
| return argumentsAction.getArguments(); | ||
| } else { | ||
| failReason = "null arguments action"; | ||
| } | ||
| return node; | ||
| } else { | ||
| failReason = "null flow node"; | ||
| } | ||
| 
        
          
        
         | 
    @@ -162,7 +182,6 @@ private Map<String, Object> getStepArguments(Run run, String nodeId) throws Ille | |
| public List<String> getInterpolatedVariables() { | ||
| return interpolatedVariables; | ||
| } | ||
| 
     | 
||
| } | ||
| 
     | 
||
| private static String argumentToString(Object arg) { | ||
| 
          
            
          
           | 
    @@ -200,9 +219,14 @@ private static String argumentToString(Object arg) { | |
| UninstantiatedDescribable ud = (UninstantiatedDescribable) arg; | ||
| Map<String, ?> udArgs = ud.getArguments(); | ||
| if (ud.getSymbol() != null) { | ||
| valueString = udArgs.entrySet().stream() | ||
| .map(InterpolatedSecretsAction::argumentToString) | ||
| .collect(Collectors.joining(", ", ud.getSymbol() + "(", ")")); | ||
| String prefix = ud.getSymbol() + "("; | ||
| if (ud.hasSoleRequiredArgument() && udArgs.size() == 1) { | ||
| valueString = prefix + argumentToString(udArgs.values().iterator().next()) + ")"; | ||
| } else { | ||
| valueString = udArgs.entrySet().stream() | ||
| .map(InterpolatedSecretsAction::argumentToString) | ||
| .collect(Collectors.joining(", ", prefix, ")")); | ||
| } | ||
| } else { | ||
| if (udArgs.isEmpty()) { | ||
| valueString = "[$class: " + ud.getKlass() + "]"; | ||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to set the
DescribableModelin order forhasSoleRequiredArgumentto work.