Skip to content

Commit 38d3af4

Browse files
author
Vincent Potucek
committed
[openrewrite] add JavaSecurityBestPractices
1 parent 180d678 commit 38d3af4

File tree

33 files changed

+140
-54
lines changed

33 files changed

+140
-54
lines changed

.github/workflows/claude.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,29 @@ jobs:
2222
with:
2323
script: |
2424
try {
25+
// Get username - prioritize sender (the person who triggered the event)
26+
const username = github.event.sender?.login ||
27+
github.event.comment?.user?.login;
28+
29+
if (!username) {
30+
console.log('Could not determine username from event payload');
31+
console.log(`Event type: ${github.event_name}`);
32+
console.log(`Event payload keys: ${Object.keys(github.event).join(', ')}`);
33+
return false;
34+
}
35+
36+
console.log(`Checking team membership for user: ${username} (triggered by ${github.event_name} event)`);
37+
2538
const { data } = await github.rest.teams.getMembershipForUserInOrg({
2639
org: 'diffplug',
2740
team_slug: 'spotless',
28-
username: github.event.sender.login
41+
username: username
2942
});
30-
console.log(`User ${github.event.sender.login} membership status: ${data.state}`);
43+
console.log(`User ${username} membership status: ${data.state}`);
3144
return data.state === 'active';
3245
} catch (error) {
33-
console.log(`User ${github.event.sender.login} is not a member of the Spotless team`);
46+
const username = github.event.sender?.login || github.event.comment?.user?.login || 'unknown user';
47+
console.log(`User ${username} is not a member of the Spotless team or error occurred: ${error.message}`);
3448
return false;
3549
}
3650

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ spotless {
3232
dependencies {
3333
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.15.0"))
3434
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.18.0")
35+
rewrite('org.openrewrite.recipe:rewrite-java-security:3.19.0')
36+
rewrite('org.openrewrite.recipe:rewrite-rewrite:0.13.0')
37+
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.17.0')
38+
rewrite('org.openrewrite.recipe:rewrite-third-party:0.27.0')
3539
}

gradle/rewrite.gradle

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
11
apply plugin: 'org.openrewrite.rewrite'
22

33
rewrite {
4-
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
4+
activeRecipe(
5+
'org.openrewrite.gradle.GradleBestPractices',
6+
'org.openrewrite.java.RemoveUnusedImports',
7+
'org.openrewrite.java.migrate.UpgradeToJava17',
8+
'org.openrewrite.java.recipes.JavaRecipeBestPractices',
9+
'org.openrewrite.java.recipes.RecipeTestingBestPractices',
10+
'org.openrewrite.java.security.JavaSecurityBestPractices',
11+
'org.openrewrite.staticanalysis.JavaApiBestPractices',
12+
'org.openrewrite.staticanalysis.LowercasePackage',
13+
'org.openrewrite.staticanalysis.MissingOverrideAnnotation',
14+
'org.openrewrite.staticanalysis.ModifierOrder',
15+
'org.openrewrite.staticanalysis.NoFinalizer',
16+
'org.openrewrite.staticanalysis.RemoveUnusedLocalVariables',
17+
'org.openrewrite.staticanalysis.RemoveUnusedPrivateFields',
18+
'org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods'
19+
// bugs
20+
// 'org.openrewrite.staticanalysis.CodeCleanup',
21+
// 'org.openrewrite.staticanalysis.CommonStaticAnalysis',
22+
)
23+
exclusions.addAll( // bugs
24+
'**_gradle_node_plugin_example_**',
25+
'**gradle/changelog.gradle',
26+
'**gradle/java-publish.gradle',
27+
'**idea/full.clean.java',
28+
'**java-setup.gradle',
29+
'**lib-extra/build.gradle',
30+
'**lib/build.gradle',
31+
'**package-info.java',
32+
'**plugin-maven/build.gradle',
33+
'**settings.gradle'
34+
)
535
exportDatatables = true
636
failOnDryRunResults = true
737
}

lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static class CachedEndings implements Serializable {
146146
private static final long serialVersionUID = -2534772773057900619L;
147147

148148
/** this is transient, to simulate PathSensitive.RELATIVE */
149-
transient final String rootDir;
149+
final transient String rootDir;
150150
/** the line ending used for most files */
151151
final String defaultEnding;
152152
/** any exceptions to that default, in terms of relative path from rootDir */

lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 DiffPlug
2+
* Copyright 2020-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -132,9 +132,9 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) {
132132
return treeWalk.idEqual(TREE, WORKDIR);
133133
}
134134

135-
private final static int TREE = 0;
136-
private final static int INDEX = 1;
137-
private final static int WORKDIR = 2;
135+
private static final int TREE = 0;
136+
private static final int INDEX = 1;
137+
private static final int WORKDIR = 2;
138138

139139
Map<File, Repository> gitRoots = new HashMap<>();
140140
Table<Repository, String, ObjectId> rootTreeShaCache = HashBasedTable.create();

lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@
2424
import com.diffplug.spotless.extra.eclipse.EquoResourceHarness;
2525

2626
public class GrEclipseFormatterStepTest extends EquoResourceHarness {
27-
private final static String INPUT = "class F{ def m(){} }";
28-
private final static String EXPECTED = "class F{\n\tdef m(){}\n}";
27+
private static final String INPUT = "class F{ def m(){} }";
28+
private static final String EXPECTED = "class F{\n\tdef m(){}\n}";
2929

3030
public GrEclipseFormatterStepTest() {
3131
super(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()));

lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.io.FileOutputStream;
2020
import java.io.IOException;
2121
import java.io.OutputStream;
22+
import java.nio.file.Files;
2223
import java.util.Properties;
2324
import java.util.function.Consumer;
2425
import java.util.stream.Stream;
@@ -33,7 +34,7 @@
3334
import com.diffplug.spotless.extra.eclipse.EclipseResourceHarness;
3435

3536
public class EclipseWtpFormatterStepTest {
36-
private final static Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support("Oldest Version").add(8, "4.8.0");
37+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support("Oldest Version").add(8, "4.8.0");
3738

3839
private static class NestedTests extends EclipseResourceHarness {
3940
private final String unformatted, formatted;
@@ -76,7 +77,7 @@ void multipleConfigurations() throws Exception {
7677
private File createPropertyFile(Consumer<Properties> config) throws IOException {
7778
Properties configProps = new Properties();
7879
config.accept(configProps);
79-
File tempFile = File.createTempFile("EclipseWtpFormatterStepTest-", ".properties");
80+
File tempFile = Files.createTempFile("EclipseWtpFormatterStepTest-", ".properties").toFile();
8081
OutputStream tempOut = new FileOutputStream(tempFile);
8182
configProps.store(tempOut, "test properties");
8283
tempOut.flush();

lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected Class<?> inferType(String input) {
5252
* @return a {@link JsonFactory}. May be overridden to handle alternative formats.
5353
* @see <a href="https://github.com/FasterXML/jackson-dataformats-text">jackson-dataformats-text</a>
5454
*/
55+
@Override
5556
protected JsonFactory makeJsonFactory() {
5657
JsonFactory jsonFactory = new JsonFactoryBuilder().build();
5758

lib/src/main/java/com/diffplug/spotless/FormatterProperties.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.stream.Collectors;
3434
import java.util.stream.IntStream;
3535

36+
import javax.xml.XMLConstants;
3637
import javax.xml.parsers.DocumentBuilder;
3738
import javax.xml.parsers.DocumentBuilderFactory;
3839
import javax.xml.parsers.ParserConfigurationException;
@@ -201,6 +202,21 @@ private Properties executeWithSupplier(Supplier<InputStream> isSupplier) throws
201202
private Node getRootNode(final InputStream is) throws IOException, IllegalArgumentException {
202203
try {
203204
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
205+
try {
206+
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
207+
208+
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
209+
210+
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
211+
212+
dbf.setXIncludeAware(false);
213+
dbf.setExpandEntityReferences(false);
214+
215+
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
216+
217+
} catch (ParserConfigurationException e) {
218+
throw new IllegalStateException("Some features are not supported by your XML processor.", e);
219+
}
204220
/*
205221
* It is not required to validate or normalize attribute values for
206222
* the XMLs currently supported. Disabling validation is supported by

lib/src/main/java/com/diffplug/spotless/NoLambda.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public interface NoLambda extends Serializable {
4444
public byte[] toBytes();
4545

4646
/** An implementation of NoLambda in which equality is based on the serialized representation of itself. */
47-
public static abstract class EqualityBasedOnSerialization implements NoLambda {
47+
public abstract static class EqualityBasedOnSerialization implements NoLambda {
4848
@Serial
4949
private static final long serialVersionUID = 1733798699224768949L;
5050

0 commit comments

Comments
 (0)