2121import java .lang .management .ManagementFactory ;
2222import java .nio .file .Path ;
2323import java .util .ArrayList ;
24+ import java .util .Arrays ;
2425import java .util .Collections ;
2526import java .util .HashMap ;
2627import java .util .List ;
28+ import java .util .Locale ;
2729import java .util .Map ;
2830import java .util .Properties ;
2931import java .util .TreeMap ;
3739 */
3840public final class BuildDefinitions {
3941
42+ /**
43+ * User-property names containing any of these substrings (case-insensitive) are omitted from attestations.
44+ *
45+ * <p>The Maven GPG plugin discourages passing credentials on the command line, but a stray {@code -Dgpg.passphrase=...} must not be captured in the
46+ * attestation if someone does it anyway.</p>
47+ */
48+ private static final List <String > SENSITIVE_KEYWORDS =
49+ Arrays .asList ("secret" , "password" , "passphrase" , "token" , "credential" );
50+
4051 /**
4152 * Reconstructs the Maven command line string from the given execution request.
53+ * User properties whose name matches {@link #SENSITIVE_KEYWORDS} are omitted.
4254 *
4355 * @param request the Maven execution request
4456 * @return a string representation of the Maven command line
@@ -49,10 +61,26 @@ static String commandLine(final MavenExecutionRequest request) {
4961 if (!profiles .isEmpty ()) {
5062 args .add ("-P" + profiles );
5163 }
52- request .getUserProperties ().forEach ((key , value ) -> args .add ("-D" + key + "=" + value ));
64+ request .getUserProperties ().forEach ((key , value ) -> {
65+ final String k = key .toString ();
66+ if (isNotSensitive (k )) {
67+ args .add ("-D" + k + "=" + value );
68+ }
69+ });
5370 return String .join (" " , args );
5471 }
5572
73+ /**
74+ * Checks if a property key is not sensitive.
75+ *
76+ * @param property A property key
77+ * @return {@code true} if the property is not considered sensitive
78+ */
79+ private static boolean isNotSensitive (final String property ) {
80+ final String lower = property .toLowerCase (Locale .ROOT );
81+ return SENSITIVE_KEYWORDS .stream ().noneMatch (lower ::contains );
82+ }
83+
5684 /**
5785 * Returns a map of external build parameters captured from the current JVM and Maven session.
5886 *
@@ -65,7 +93,7 @@ public static Map<String, Object> externalParameters(final MavenSession session)
6593 final MavenExecutionRequest request = session .getRequest ();
6694 params .put ("maven.goals" , request .getGoals ());
6795 params .put ("maven.profiles" , request .getActiveProfiles ());
68- params .put ("maven.user.properties" , request . getUserProperties ());
96+ params .put ("maven.user.properties" , getUserProperties (request ));
6997 params .put ("maven.cmdline" , commandLine (request ));
7098 final Map <String , Object > env = new HashMap <>();
7199 params .put ("env" , env );
@@ -78,6 +106,23 @@ public static Map<String, Object> externalParameters(final MavenSession session)
78106 return params ;
79107 }
80108
109+ /**
110+ * Returns a filtered map of user properties.
111+ *
112+ * @param request A Maven request
113+ * @return A map of user properties.
114+ */
115+ private static TreeMap <String , String > getUserProperties (final MavenExecutionRequest request ) {
116+ final TreeMap <String , String > properties = new TreeMap <>();
117+ request .getUserProperties ().forEach ((k , value ) -> {
118+ final String key = k .toString ();
119+ if (isNotSensitive (key )) {
120+ properties .put (key , value .toString ());
121+ }
122+ });
123+ return properties ;
124+ }
125+
81126 /**
82127 * Creates a {@link ResourceDescriptor} for the JDK used during the build.
83128 *
0 commit comments