OpenAS2 / OpenAs2App

OpenAS2 is a java-based implementation of the EDIINT AS2 standard. It is intended to be used as a server. It is extremely configurable and supports a wide variety of signing and encryption algorithms.
https://sourceforge.net/projects/openas2/
GNU General Public License v3.0
185 stars 137 forks source link

Null pointer Exception thrown if the received message header does not have file name #240

Closed myedigateway closed 3 years ago

myedigateway commented 3 years ago

2021-10-07 19:24:19.883 FINE AS2ReceiverHandler: Error receiving message for inbound AS2 request. There is no data. [null] org.openas2.OpenAS2Exception: Missing data in AS2 request. at org.openas2.processor.receiver.AS2ReceiverHandler.handle(AS2ReceiverHandler.java:123) at org.openas2.processor.receiver.NetModule$ConnectionHandler.run(NetModule.java:176) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

Recreated by doing a quick test on the method :

public static void testCleanFilename() throws Exception {
    IOUtil.cleanFilename(null);
}

public static String cleanFilename(String filename) {
    /*
     * byte[] fnBytes = filename.getBytes(); byte c;
     *
     * for (int i = 0; i < fnBytes.length; i++) { c = fnBytes[i];
     *
     * if (VALID_FILENAME_CHARS.indexOf(c) == -1) { fnBytes[i] = '_'; } }
     *
     * return new String(fnBytes);
     */
    String reservedFilenameChars = Properties.getProperty("reservedFilenameCharacters", "<>:\"|?*");
    if (reservedFilenameChars != null && reservedFilenameChars.length() > 0) {
        String srchReplStr = reservedFilenameChars.replaceAll("\\[", "\\[").replaceAll("\\]", "\\]");
        if (reservedFilenameChars.contains(":") && filename.matches("^[a-zA-Z]{1}:.*")) {
            filename = filename.substring(0, 2) + filename.substring(2).replaceAll("[" + srchReplStr + "]", "");
        } else {
            filename = filename.replaceAll("[" + srchReplStr + "]", "");
        }
        // also remove control characters
        filename = filename.replaceAll("[\u0000-\u001F]", "");
    }
    return filename;
}
uhurusurfa commented 3 years ago

The error you are seeing is if the HTTP POST contains no post data.

This is the code that extracts the file name from the received AS2 message:

                    try {
                        // Extract and Store the received filename of the payload
                        String filename = msg.extractPayloadFilename();
                        // check for a fallback if not able to extract from content-disposition
                        if (filename == null || filename.length() == 0) {
                            filename = Properties.getProperty(Properties.AS2_RX_MESSAGE_FILENAME_FALLBACK, null);
                            if (filename == null) {
                                filename = msg.getMessageID();
                            } else {
                                CompositeParameters parser = new CompositeParameters(false).add("date", new DateParameters()).add("msg", new MessageParameters(msg)).add("rand", new RandomParameters());
                                filename = ParameterParser.parse(filename, parser);
                            }
                        }
                        msg.setPayloadFilename(filename);
                    } catch (ParseException e1) {
                        LOG.error("Failed to extract the file name from received content-disposition", e1);
                    }

As you can see, if it does not manage to create a file name for the inbound file it will throw a different message to what you are seeing.