|
| 1 | +/** |
| 2 | + * Provides classes for modelling Torrent libraries. |
| 3 | + */ |
| 4 | + |
| 5 | +import javascript |
| 6 | + |
| 7 | +/** |
| 8 | + * Provides classes for working with [parse-torrent](https://github.com/webtorrent/parse-torrent) code. |
| 9 | + */ |
| 10 | +module ParseTorrent { |
| 11 | + private DataFlow::SourceNode mod() { result = DataFlow::moduleImport("parse-torrent") } |
| 12 | + |
| 13 | + /** |
| 14 | + * A torrent that has been parsed into a JavaScript object. |
| 15 | + */ |
| 16 | + class ParsedTorrent extends DataFlow::SourceNode { |
| 17 | + ParsedTorrent() { |
| 18 | + this = mod().getACall() or |
| 19 | + this = mod().getAMemberCall("remote").getCallback(1).getParameter(1) |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + private DataFlow::SourceNode parsedTorrentRef(DataFlow::TypeTracker t) { |
| 24 | + t.start() and |
| 25 | + result instanceof ParsedTorrent |
| 26 | + or |
| 27 | + exists(DataFlow::TypeTracker t2 | result = parsedTorrentRef(t2).track(t2, t)) |
| 28 | + } |
| 29 | + |
| 30 | + /** Gets a data flow node referring to a parsed torrent. */ |
| 31 | + DataFlow::SourceNode parsedTorrentRef() { |
| 32 | + result = parsedTorrentRef(DataFlow::TypeTracker::end()) |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * An access to user-controlled torrent information. |
| 37 | + */ |
| 38 | + class UserControlledTorrentInfo extends RemoteFlowSource { |
| 39 | + UserControlledTorrentInfo() { |
| 40 | + exists(DataFlow::SourceNode ref, DataFlow::PropRead read | |
| 41 | + ref = parsedTorrentRef() and |
| 42 | + read = ref.getAPropertyRead() and |
| 43 | + this = read |
| 44 | + | |
| 45 | + exists(string prop | |
| 46 | + not ( |
| 47 | + prop = "private" or |
| 48 | + prop = "infoHash" or |
| 49 | + prop = "length" |
| 50 | + // "pieceLength" and "lastPieceLength" are not guaranteed to be numbers as of commit ae3ad15d |
| 51 | + ) and |
| 52 | + read.getPropertyName() = prop |
| 53 | + ) |
| 54 | + or |
| 55 | + not exists(read.getPropertyName()) |
| 56 | + ) |
| 57 | + } |
| 58 | + |
| 59 | + override string getSourceType() { result = "torrent information" } |
| 60 | + } |
| 61 | +} |
0 commit comments