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

Add object input filter on Connector #1000

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/run-build-with-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup JDK 8
- name: Setup JDK 11
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8.0.345'
java-version: '11.0.22'
architecture: x64
cache: 'gradle'

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ subprojects {
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 11
targetCompatibility = 11

ext {
profile = project.hasProperty("profile") ? profile : "production"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputFilter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
Expand All @@ -31,6 +32,8 @@
import java.net.UnknownHostException;

import net.grinder.common.UncheckedInterruptedException;
import net.grinder.common.processidentity.ProcessIdentity;
import net.grinder.engine.controller.AbstractAgentControllerIdentityImplementation;


/**
Expand Down Expand Up @@ -197,6 +200,23 @@ static ConnectDetails read(InputStream in) throws CommunicationException {

try {
final ObjectInputStream objectInputStream = new ObjectInputStream(in);
objectInputStream.setObjectInputFilter(filterInfo -> {
if (filterInfo.serialClass() == null) {
return ObjectInputFilter.Status.UNDECIDED;
}

if (Address.class.isAssignableFrom(filterInfo.serialClass())
|| ConnectionType.class.isAssignableFrom(filterInfo.serialClass())
|| Enum.class.isAssignableFrom(filterInfo.serialClass())
|| filterInfo.serialClass().getCanonicalName().startsWith("net.grinder.engine")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be attacked if class name is net.grinder.engine.Attacker.java?

|| filterInfo.serialClass().getCanonicalName().startsWith("net.grinder.common")
) {
return ObjectInputFilter.Status.ALLOWED;
}

return ObjectInputFilter.Status.REJECTED;
});

final ConnectionType type =
(ConnectionType) objectInputStream.readObject();
final Address address = (Address) objectInputStream.readObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
*/
package org.ngrinder.dns;

import org.xbill.DNS.*;
import org.xbill.DNS.ARecord;
import org.xbill.DNS.Cache;
import org.xbill.DNS.DClass;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.PTRRecord;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;

import java.net.InetAddress;
import java.net.UnknownHostException;
Expand Down
Loading