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

Fix the risks found by PenTest #76

Merged
merged 7 commits into from
Oct 7, 2021
Merged

Fix the risks found by PenTest #76

merged 7 commits into from
Oct 7, 2021

Conversation

spbjss
Copy link
Contributor

@spbjss spbjss commented Aug 25, 2021

Description

Fix the risks found by PenTest
1. unhandled 500 server error.
2. Insecure Deserialization

Issues Resolved

#73
#74

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Alex and others added 6 commits August 10, 2021 16:48
Signed-off-by: Alex <pengsun@amazon.com>
the conflict with search XContent input.

Signed-off-by: Alex <pengsun@amazon.com>
1. unhandled 500 server error.
2. Insecure Deserialization

Signed-off-by: Alex <pengsun@amazon.com>
"*java.time.*",
"*org.tribuo.*",
"*com.oracle.labs.*",
"[*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, it's a workaround of an issue of the tribuo library.

Issue:
If we serialize the KMeansModel using ObjectOutputStream and ByteArrayOutputStream to a byte array, when we
deserialize the byte[] to an Object using ObjectInputStream and ObjectInputStream, we will see some strange class names, like: "[D", "[I" and "[Lorg.tribuo.math.la.DenseVector".
Reference:
https://github.com/R3Conclave/conclave-samples/blob/6da1a92acc8d2a51975475c1ffe507e6cdfcaa08/tribuo-tutorials/enclave/src/main/resources/META-INF/native-image/serialization-config.json
Workaround Solution:
We have to put "[D", "[I" and "[Lorg.tribuo.math.la.DenseVector" to the whitelist, otherwise the validation will run failed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we'd better add concrete class path here to avoid some malicious code using this pattern.

import java.io.ObjectOutputStream;

@UtilityClass
public class ModelSerDeSer {
// Welcome list includes OpenSearch ml plugin classes, JDK common classes and Tribuo libraries.
public static final String[] ACCEPT_CLASS_PATTERNS = {
"*org.opensearch.ml.*",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why need to add "*" as prefix?

ValidatingObjectInputStream validatingObjectInputStream = new ValidatingObjectInputStream(inputStream);

// Validate the model class type to avoid deserialization attack.
validatingObjectInputStream.accept(ACCEPT_CLASS_PATTERNS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If someone wrote class with the same class path, for example "org.opensearch.ml.SomeHackClass" . Can this prevent that deserialization attack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this validation only validate the package/class name

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not security expert, but I feel we'd better add concrete class names to avoid some one write malicious code with these allowed patterns.

Copy link
Collaborator

@ylwu-amzn ylwu-amzn left a comment

Choose a reason for hiding this comment

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

LGTM. Suggest to ask security team to help review as well.

@spbjss spbjss merged commit 1710140 into opensearch-project:develop Oct 7, 2021
jackiehanyang pushed a commit that referenced this pull request Nov 16, 2021
* Create JvmService instance on demand.

Signed-off-by: Alex <pengsun@amazon.com>

* Move the ml_parameters from XContent to the request parameters to avoid
the conflict with search XContent input.

Signed-off-by: Alex <pengsun@amazon.com>

* Fix the security risks found by PenTest.
1. unhandled 500 server error.
2. Insecure Deserialization

Signed-off-by: Alex <pengsun@amazon.com>

* Remove unnecessory '*' from the welcome list of model deserializer.

Signed-off-by: Alex <pengsun@amazon.com>

Co-authored-by: Alex <pengsun@amazon.com>
@ylwu-amzn ylwu-amzn added the bug Something isn't working label Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants