-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2cb320
commit 22ec4ac
Showing
5 changed files
with
88 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/java/jenkins/security/ExtendedReadRedaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package jenkins.security; | ||
|
||
import hudson.ExtensionList; | ||
import hudson.ExtensionPoint; | ||
|
||
/** | ||
* Redact {@code config.xml} contents for users with ExtendedRead permission | ||
* while lacking the required Configure permission to see the full unredacted | ||
* configuration. | ||
* | ||
* @see <a href="https://issues.jenkins.io/browse/SECURITY-266">SECURITY-266</a> | ||
* @see <a href="https://www.jenkins.io/security/advisory/2016-05-11/">Jenkins Security Advisory 2016-05-11</a> | ||
* @since TODO | ||
*/ | ||
public interface ExtendedReadRedaction extends ExtensionPoint { | ||
/** | ||
* Redacts sensitive information from the provided {@code config.xml} file content. | ||
* Input may already have redactions applied; output may be passed through further redactions. | ||
* These methods are expected to retain the basic structure of the XML document contained in input/output strings. | ||
* | ||
* @param configDotXml String representation of (potentially already redacted) config.xml file | ||
* @return Redacted config.xml file content | ||
*/ | ||
String apply(String configDotXml); | ||
|
||
static ExtensionList<ExtendedReadRedaction> all() { | ||
return ExtensionList.lookup(ExtendedReadRedaction.class); | ||
} | ||
|
||
static String applyAll(String configDotXml) { | ||
for (ExtendedReadRedaction redaction : all()) { | ||
configDotXml = redaction.apply(configDotXml); | ||
} | ||
return configDotXml; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
core/src/main/java/jenkins/security/ExtendedReadSecretRedaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package jenkins.security; | ||
|
||
import hudson.Extension; | ||
import hudson.util.Secret; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Restricted(NoExternalUse.class) | ||
@Extension | ||
public class ExtendedReadSecretRedaction implements ExtendedReadRedaction { | ||
|
||
private static final Pattern SECRET_PATTERN = Pattern.compile(">(" + Secret.ENCRYPTED_VALUE_PATTERN + ")<"); | ||
|
||
@Override | ||
public String apply(String configDotXml) { | ||
Matcher matcher = SECRET_PATTERN.matcher(configDotXml); | ||
StringBuilder cleanXml = new StringBuilder(); | ||
while (matcher.find()) { | ||
if (Secret.decrypt(matcher.group(1)) != null) { | ||
matcher.appendReplacement(cleanXml, ">********<"); | ||
} | ||
} | ||
matcher.appendTail(cleanXml); | ||
return cleanXml.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters