Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-120

Fix security issues in serialization code for Random instances

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.3
    • 1.3
    • core, simple
    • None

    Description

      SonarCloud has highlighted security issues in the use of serialization to save and restore the state of java.util.Random instances.

      When reading objects using ObjectInputStream.readObject() the class is first identified and the private readObject() method of the class type is executed (if it is present). If the class is a malicious class then potentially malicious code can be executed.

      JDKRandom

      Uses serialisation to save the java.util.Random instance to the RandomProviderState.

      The code requires that java.util.Random is read using ObjectInputStream.readObject(). To ensure the code only allows java.util.Random to be read the code can adapt the ValidatingObjectInputStream idea from Commons IO to prevent malicious code execution.

      JDKRandomBridge

      This writes and reads a byte[] using the writeObject and readObject methods of ObjectOutput/InputStream. To avoid use of readObject() the code can be refactored to write the byte[] using the write(byte[]) method of ObjectOutputStream and the readFully(byte[]) method of ObjectInputStream.

      Attachments

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m