Skip to content
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

[SECURITY-2053] Prevent plain text credentials of Basic/Digest authentication #105

Merged
merged 13 commits into from
Aug 1, 2022
Merged
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ THE SOFTWARE.
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/http-request-plugin</gitHubRepo>
<jenkins.version>2.249.1</jenkins.version>
<hpi.compatibleSinceVersion>1.8.17</hpi.compatibleSinceVersion>
<hpi.compatibleSinceVersion>1.16</hpi.compatibleSinceVersion>
</properties>

<repositories>
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/jenkins/plugins/http_request/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,6 @@ public static ListBoxModel fillAuthenticationItems(Item project, String url) {
}

List<Option> options = new ArrayList<>();
for (BasicDigestAuthentication basic : HttpRequestGlobalConfig.get().getBasicDigestAuthentications()) {
options.add(new Option("(deprecated - use Jenkins Credentials) " +
basic.getKeyName(), basic.getKeyName()));
}

for (FormAuthentication formAuthentication : HttpRequestGlobalConfig.get().getFormAuthentications()) {
options.add(new Option(formAuthentication.getKeyName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
@Extension
public class HttpRequestGlobalConfig extends GlobalConfiguration {

private List<BasicDigestAuthentication> basicDigestAuthentications = new ArrayList<>();
/**
* @deprecated removed without replacement
*/
@Deprecated
private transient List<BasicDigestAuthentication> basicDigestAuthentications = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage of deprecated field still present in HttpRequestGlobalConfig#getAuthentications

Copy link
Contributor Author

@offa offa Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the usage from getAuthentications(). The other two usages are getter and setter.

What is the best scenario for those? If getter / setter are deprecated but still available I'd suggest keeping the related test cases too (it's still some kind of public API), or remove getter, setter, field (?) and related tests altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all callers of deprecated methods but retain the methods for binary compatibility

private List<FormAuthentication> formAuthentications = new ArrayList<>();

private static final XStream2 XSTREAM2 = new XStream2();
Expand Down Expand Up @@ -78,10 +82,18 @@ public static HttpRequestGlobalConfig get() {
return GlobalConfiguration.all().get(HttpRequestGlobalConfig.class);
}

/**
* @deprecated removed without replacement
*/
@Deprecated
public List<BasicDigestAuthentication> getBasicDigestAuthentications() {
offa marked this conversation as resolved.
Show resolved Hide resolved
return basicDigestAuthentications;
}

/**
* @deprecated removed without replacement
*/
@Deprecated
public void setBasicDigestAuthentications(
offa marked this conversation as resolved.
Show resolved Hide resolved
List<BasicDigestAuthentication> basicDigestAuthentications) {
this.basicDigestAuthentications = basicDigestAuthentications;
Expand All @@ -97,10 +109,7 @@ public void setFormAuthentications(
}

public List<Authenticator> getAuthentications() {
List<Authenticator> list = new ArrayList<>();
list.addAll(basicDigestAuthentications);
list.addAll(formAuthentications);
return list;
return new ArrayList<>(formAuthentications);
}

public Authenticator getAuthentication(String keyName) {
Expand All @@ -111,4 +120,9 @@ public Authenticator getAuthentication(String keyName) {
}
return null;
}

protected Object readResolve() {
this.basicDigestAuthentications = new ArrayList<>();
offa marked this conversation as resolved.
Show resolved Hide resolved
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,6 @@
</d:tag>
</d:taglib>
<f:section title="HTTP Request">
<f:entry title="DEPRECATED (use Jenkins credentials) Basic/Digest Authentication">
<f:repeatable field="basicDigestAuthentications">
<local:blockWrapper>
<f:entry title="Key Name" field="keyName" help="/plugin/http_request/help-keyName.html">
<f:textbox />
</f:entry>
<f:entry title="Username" field="userName" help="/plugin/http_request/help-userName.html">
<f:textbox />
</f:entry>
<f:entry title="Password" field="password" help="/plugin/http_request/help-password.html">
<f:password />
</f:entry>
<f:entry title="">
<div align="right">
<f:repeatableDeleteButton />
</div>
</f:entry>
</local:blockWrapper>
</f:repeatable>
</f:entry>

<f:entry title="Form Authentication">
<f:repeatable field="formAuthentications">
<local:blockWrapper>
Expand Down
3 changes: 0 additions & 3 deletions src/main/webapp/help-password.html

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/webapp/help-userName.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,7 @@ public void populatedGlobalConfig() {
HttpRequestGlobalConfig cfg = HttpRequestGlobalConfig.get();

List<BasicDigestAuthentication> bdas = cfg.getBasicDigestAuthentications();
assertEquals(2,bdas.size());
Iterator<BasicDigestAuthentication> itr = bdas.iterator();
BasicDigestAuthentication bda = itr.next();
assertEquals("k1",bda.getKeyName());
assertEquals("u1",bda.getUserName());
assertEquals("p1",bda.getPassword());
bda = itr.next();
assertEquals("k2",bda.getKeyName());
assertEquals("u2",bda.getUserName());
assertEquals("p2",bda.getPassword());
assertEquals(0,bdas.size());

List<FormAuthentication> fas = cfg.getFormAuthentications();
assertEquals(1,fas.size());
Expand Down