|
8 | 8 | import com.launchdarkly.sdk.server.interfaces.DataSource;
|
9 | 9 | import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider;
|
10 | 10 | import com.launchdarkly.sdk.server.interfaces.DataStore;
|
| 11 | +import com.launchdarkly.testhelpers.TempFile; |
11 | 12 |
|
12 | 13 | import org.junit.Test;
|
13 | 14 |
|
|
29 | 30 | import static com.launchdarkly.sdk.server.integrations.FileDataSourceTestData.resourceFilePath;
|
30 | 31 | import static org.hamcrest.MatcherAssert.assertThat;
|
31 | 32 | import static org.hamcrest.Matchers.equalTo;
|
| 33 | +import static org.hamcrest.Matchers.is; |
32 | 34 | import static org.junit.Assert.assertEquals;
|
33 | 35 |
|
34 | 36 | @SuppressWarnings("javadoc")
|
@@ -142,4 +144,28 @@ private void verifyUnsuccessfulStart(DataSource fp) {
|
142 | 144 | DataSourceStatusProvider.Status status = requireDataSourceStatus(statuses, DataSourceStatusProvider.State.INITIALIZING);
|
143 | 145 | assertEquals(DataSourceStatusProvider.ErrorKind.INVALID_DATA, status.getLastError().getKind());
|
144 | 146 | }
|
| 147 | + |
| 148 | + @Test |
| 149 | + public void instantiationOfArbitraryTypeIsNotAllowed() throws Exception { |
| 150 | + // test for https://nvd.nist.gov/vuln/detail/CVE-2022-1471 - this test fails if we use the |
| 151 | + // empty Yaml() constructor in FileDataSourceParsing |
| 152 | + String className = SimulatedMaliciousType.class.getName(); |
| 153 | + Class.forName(this.getClass().getName()); |
| 154 | + Class.forName(className); |
| 155 | + try (TempFile f = TempFile.create()) { |
| 156 | + f.setContents("---\nbad_thing: !!" + className + " [value]\n"); |
| 157 | + try (DataSource fp = makeDataSource(FileData.dataSource().filePaths(f.getPath()))) { |
| 158 | + verifyUnsuccessfulStart(fp); |
| 159 | + assertThat(SimulatedMaliciousType.wasInstantiated, is(false)); |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + public static class SimulatedMaliciousType { |
| 165 | + static volatile boolean wasInstantiated = false; |
| 166 | + |
| 167 | + public SimulatedMaliciousType(String value) { |
| 168 | + wasInstantiated = true; |
| 169 | + } |
| 170 | + } |
145 | 171 | }
|
0 commit comments