Skip to content

Commit

Permalink
feat: add option to mask header values
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyNoble committed Dec 10, 2024
1 parent f98121f commit 5901dd8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
35 changes: 18 additions & 17 deletions src/main/java/org/jenkinsci/plugins/urltrigger/URLTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ private boolean checkIfModifiedEntryForHttpOrHttpsURL(URLTriggerResolvedEntry re
List< URLTriggerRequestHeader > requestHeaders = resolvedEntry.getEntry().getRequestHeaders() ;
if( requestHeaders.size() > 0 ) {
for( URLTriggerRequestHeader requestHeader : requestHeaders ) {
log.info("Adding header - " + requestHeader.headerName + ":" + requestHeader.headerValue) ;
String safeValue = requestHeader.maskValue ? "<MASKED>" : requestHeader.headerValue ;
log.info("Adding header - " + requestHeader.headerName + ":" + safeValue) ;
webResourceBuilder = webResourceBuilder.header(requestHeader.headerName, requestHeader.headerValue) ;
}
}
Expand Down Expand Up @@ -684,25 +685,25 @@ private URLTriggerEntry fillAndGetEntry(StaplerRequest req, JSONObject entryObje
//Process requestHeaders
List< URLTriggerRequestHeader > requestHeaders = new ArrayList<>() ;
Object requestHeaderListObject = entryObject.get("urlRequestHeaders") ;
JSONArray requestHeaderListArray;
if( requestHeaderListObject instanceof JSONObject ) {
JSONObject requestHeaderItem = (JSONObject) requestHeaderListObject ;
String headerName = Util.fixEmpty(requestHeaderItem.getString("headerName")) ;
String headerValue = Util.fixEmpty(requestHeaderItem.getString("headerValue" )) ;
if( headerName != null && headerValue != null ) {
requestHeaders.add( new URLTriggerRequestHeader( headerName , headerValue ) ) ;
}
requestHeaderListArray = new JSONArray();
requestHeaderListArray.add( requestHeaderListObject );
} else {
JSONArray requestHeaderListArray = (JSONArray) requestHeaderListObject ;
if( requestHeaderListArray != null ) {
for( Object requestHeaderItemObject : requestHeaderListArray ) {
JSONObject requestHeaderItem = (JSONObject) requestHeaderItemObject ;
String headerName = Util.fixEmpty(requestHeaderItem.getString("headerName")) ;
String headerValue = Util.fixEmpty(requestHeaderItem.getString("headerValue" )) ;
if( headerName != null && headerValue != null ) {
requestHeaders.add( new URLTriggerRequestHeader( headerName , headerValue ) ) ;
} }
}
requestHeaderListArray = (JSONArray) requestHeaderListObject ;
}

if( requestHeaderListArray != null ) {
for( Object requestHeaderItemObject : requestHeaderListArray ) {
JSONObject requestHeaderItem = (JSONObject) requestHeaderItemObject ;
String headerName = Util.fixEmpty(requestHeaderItem.getString("headerName")) ;
String headerValue = Util.fixEmpty(requestHeaderItem.getString("headerValue" )) ;
if( headerName != null && headerValue != null ) {
requestHeaders.add( new URLTriggerRequestHeader( headerName , headerValue , requestHeaderItem.getBoolean("maskValue")) ) ;
}
}
}

urlTriggerEntry.setRequestHeaders(requestHeaders);

//Process inspectingContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ public class URLTriggerRequestHeader implements Serializable, Describable<URLTri
private static final long serialVersionUID = -4013307449944349433L;
@Exported public String headerName = "";
@Exported public String headerValue = "";

@Exported public boolean maskValue = false ;

public boolean isMaskValue() {
return maskValue;
}

@DataBoundSetter
public void setMaskValue(boolean maskHeader) {
this.maskValue = maskHeader;
}

public String getHeaderName() {
return headerName;
}
Expand All @@ -40,9 +50,10 @@ public void setHeaderValue(String headerValue) {
}

@DataBoundConstructor
public URLTriggerRequestHeader(String headerName, String headerValue) {
public URLTriggerRequestHeader(String headerName, String headerValue, boolean maskValue) {
this.headerName=headerName;
this.headerValue=headerValue;
this.maskValue=maskValue;
}

public Descriptor<URLTriggerRequestHeader> getDescriptor() {
Expand All @@ -61,7 +72,7 @@ public String getDisplayName() {
}

public static URLTriggerRequestHeader[] getDefaults() {
return new URLTriggerRequestHeader[] { new URLTriggerRequestHeader( "" , "" ) } ;
return new URLTriggerRequestHeader[] { new URLTriggerRequestHeader( "" , "" , false) } ;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
<f:entry title="${%Header value}" field="headerValue">
<f:textbox value="${urlRequestHeaders.headerValue}"/>
</f:entry>
<f:entry title="">
<f:checkbox
field="maskValue"
name="urlRequestHeaders.maskValue"
checked="${urlRequestHeaders.maskValue}"
title="${%Mask value of header in logs}"/>
</f:entry>
<f:entry title="">
<div align="right">
<f:repeatableDeleteButton/>
Expand Down

0 comments on commit 5901dd8

Please sign in to comment.