|
| 1 | +/** |
| 2 | + * This model covers JMS API versions 1 and 2. |
| 3 | + * |
| 4 | + * https://docs.oracle.com/javaee/6/api/javax/jms/package-summary.html |
| 5 | + * https://docs.oracle.com/javaee/7/api/javax/jms/package-summary.html |
| 6 | + */ |
| 7 | + |
| 8 | +import java |
| 9 | +private import semmle.code.java.dataflow.ExternalFlow |
| 10 | + |
| 11 | +/** Defines sources of tainted data in JMS 1. */ |
| 12 | +private class Jms1Source extends SourceModelCsv { |
| 13 | + override predicate row(string row) { |
| 14 | + row = |
| 15 | + [ |
| 16 | + // incoming messages are considered tainted |
| 17 | + "javax.jms;MessageListener;true;onMessage;(Message);;Parameter[0];remote", |
| 18 | + "javax.jms;MessageConsumer;true;receive;;;ReturnValue;remote", |
| 19 | + "javax.jms;MessageConsumer;true;receiveNoWait;();;ReturnValue;remote", |
| 20 | + "javax.jms;QueueRequestor;true;request;(Message);;ReturnValue;remote", |
| 21 | + "javax.jms;TopicRequestor;true;request;(Message);;ReturnValue;remote", |
| 22 | + ] |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +/** Defines taint propagation steps in JMS 1. */ |
| 27 | +private class Jms1FlowStep extends SummaryModelCsv { |
| 28 | + override predicate row(string row) { |
| 29 | + row = |
| 30 | + [ |
| 31 | + // if a message is tainted, then it returns tainted data |
| 32 | + "javax.jms;Message;true;getBody;();;Argument[-1];ReturnValue;taint", |
| 33 | + "javax.jms;Message;true;getJMSCorrelationIDAsBytes;();;Argument[-1];ReturnValue;taint", |
| 34 | + "javax.jms;Message;true;getJMSCorrelationID;();;Argument[-1];ReturnValue;taint", |
| 35 | + "javax.jms;Message;true;getJMSReplyTo;();;Argument[-1];ReturnValue;taint", |
| 36 | + "javax.jms;Message;true;getJMSDestination;();;Argument[-1];ReturnValue;taint", |
| 37 | + "javax.jms;Message;true;getJMSType;();;Argument[-1];ReturnValue;taint", |
| 38 | + "javax.jms;Message;true;getBooleanProperty;();;Argument[-1];ReturnValue;taint", |
| 39 | + "javax.jms;Message;true;getByteProperty;();;Argument[-1];ReturnValue;taint", |
| 40 | + "javax.jms;Message;true;getShortProperty;();;Argument[-1];ReturnValue;taint", |
| 41 | + "javax.jms;Message;true;getIntProperty;();;Argument[-1];ReturnValue;taint", |
| 42 | + "javax.jms;Message;true;getLongProperty;();;Argument[-1];ReturnValue;taint", |
| 43 | + "javax.jms;Message;true;getFloatProperty;();;Argument[-1];ReturnValue;taint", |
| 44 | + "javax.jms;Message;true;getDoubleProperty;();;Argument[-1];ReturnValue;taint", |
| 45 | + "javax.jms;Message;true;getStringProperty;();;Argument[-1];ReturnValue;taint", |
| 46 | + "javax.jms;Message;true;getObjectProperty;();;Argument[-1];ReturnValue;taint", |
| 47 | + "javax.jms;Message;true;getPropertyNames;();;Argument[-1];ReturnValue;taint", |
| 48 | + "javax.jms;BytesMessage;true;readBoolean;();;Argument[-1];ReturnValue;taint", |
| 49 | + "javax.jms;BytesMessage;true;readByte;();;Argument[-1];ReturnValue;taint", |
| 50 | + "javax.jms;BytesMessage;true;readUnsignedByte;();;Argument[-1];ReturnValue;taint", |
| 51 | + "javax.jms;BytesMessage;true;readShort;();;Argument[-1];ReturnValue;taint", |
| 52 | + "javax.jms;BytesMessage;true;readUnsignedShort;();;Argument[-1];ReturnValue;taint", |
| 53 | + "javax.jms;BytesMessage;true;readChar;();;Argument[-1];ReturnValue;taint", |
| 54 | + "javax.jms;BytesMessage;true;readInt;();;Argument[-1];ReturnValue;taint", |
| 55 | + "javax.jms;BytesMessage;true;readLong;();;Argument[-1];ReturnValue;taint", |
| 56 | + "javax.jms;BytesMessage;true;readFloat;();;Argument[-1];ReturnValue;taint", |
| 57 | + "javax.jms;BytesMessage;true;readDouble;();;Argument[-1];ReturnValue;taint", |
| 58 | + "javax.jms;BytesMessage;true;readUTF;();;Argument[-1];ReturnValue;taint", |
| 59 | + "javax.jms;BytesMessage;true;readBytes;;;Argument[-1];Argument[0];taint", |
| 60 | + "javax.jms;MapMessage;true;getBoolean;(String);;Argument[-1];ReturnValue;taint", |
| 61 | + "javax.jms;MapMessage;true;getByte;(String);;Argument[-1];ReturnValue;taint", |
| 62 | + "javax.jms;MapMessage;true;getShort;(String);;Argument[-1];ReturnValue;taint", |
| 63 | + "javax.jms;MapMessage;true;getChar;(String);;Argument[-1];ReturnValue;taint", |
| 64 | + "javax.jms;MapMessage;true;getInt;(String);;Argument[-1];ReturnValue;taint", |
| 65 | + "javax.jms;MapMessage;true;getLong;(String);;Argument[-1];ReturnValue;taint", |
| 66 | + "javax.jms;MapMessage;true;getFloat;(String);;Argument[-1];ReturnValue;taint", |
| 67 | + "javax.jms;MapMessage;true;getDouble;(String);;Argument[-1];ReturnValue;taint", |
| 68 | + "javax.jms;MapMessage;true;getString;(String);;Argument[-1];ReturnValue;taint", |
| 69 | + "javax.jms;MapMessage;true;getBytes;(String);;Argument[-1];ReturnValue;taint", |
| 70 | + "javax.jms;MapMessage;true;getObject;(String);;Argument[-1];ReturnValue;taint", |
| 71 | + "javax.jms;MapMessage;true;getMapNames;();;Argument[-1];ReturnValue;taint", |
| 72 | + "javax.jms;ObjectMessage;true;getObject;();;Argument[-1];ReturnValue;taint", |
| 73 | + "javax.jms;StreamMessage;true;readBoolean;();;Argument[-1];ReturnValue;taint", |
| 74 | + "javax.jms;StreamMessage;true;readByte;();;Argument[-1];ReturnValue;taint", |
| 75 | + "javax.jms;StreamMessage;true;readShort;();;Argument[-1];ReturnValue;taint", |
| 76 | + "javax.jms;StreamMessage;true;readChar;();;Argument[-1];ReturnValue;taint", |
| 77 | + "javax.jms;StreamMessage;true;readInt;();;Argument[-1];ReturnValue;taint", |
| 78 | + "javax.jms;StreamMessage;true;readLong;();;Argument[-1];ReturnValue;taint", |
| 79 | + "javax.jms;StreamMessage;true;readFloat;();;Argument[-1];ReturnValue;taint", |
| 80 | + "javax.jms;StreamMessage;true;readDouble;();;Argument[-1];ReturnValue;taint", |
| 81 | + "javax.jms;StreamMessage;true;readString;();;Argument[-1];ReturnValue;taint", |
| 82 | + "javax.jms;StreamMessage;true;readBytes;(byte[]);;Argument[-1];Argument[0];taint", |
| 83 | + "javax.jms;StreamMessage;true;readObject;();;Argument[-1];ReturnValue;taint", |
| 84 | + "javax.jms;TextMessage;true;getText;();;Argument[-1];ReturnValue;taint", |
| 85 | + // if a destination is tainted, then it returns tainted data |
| 86 | + "javax.jms;Queue;true;getQueueName;();;Argument[-1];ReturnValue;taint", |
| 87 | + "javax.jms;Queue;true;toString;();;Argument[-1];ReturnValue;taint", |
| 88 | + "javax.jms;Topic;true;getTopicName;();;Argument[-1];ReturnValue;taint", |
| 89 | + "javax.jms;Topic;true;toString;();;Argument[-1];ReturnValue;taint", |
| 90 | + ] |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +/** Defines additional sources of tainted data in JMS 2. */ |
| 95 | +private class Jms2Source extends SourceModelCsv { |
| 96 | + override predicate row(string row) { |
| 97 | + row = |
| 98 | + [ |
| 99 | + "javax.jms;JMSConsumer;true;receive;;;ReturnValue;remote", |
| 100 | + "javax.jms;JMSConsumer;true;receiveBody;;;ReturnValue;remote", |
| 101 | + "javax.jms;JMSConsumer;true;receiveNoWait;();;ReturnValue;remote", |
| 102 | + "javax.jms;JMSConsumer;true;receiveBodyNoWait;();;ReturnValue;remote", |
| 103 | + ] |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +/** Defines additional taint propagation steps in JMS 2. */ |
| 108 | +private class Jms2FlowStep extends SummaryModelCsv { |
| 109 | + override predicate row(string row) { |
| 110 | + row = "javax.jms;Message;true;getBody;();;Argument[-1];ReturnValue;taint" |
| 111 | + } |
| 112 | +} |
0 commit comments