|
3 | 3 | */
|
4 | 4 |
|
5 | 5 | import javascript
|
| 6 | +import semmle.javascript.frameworks.ReadableStream |
6 | 7 |
|
7 | 8 | /**
|
8 |
| - * A source of remote flow from the `Busboy` library. |
| 9 | + * A module for modeling [busboy](https://www.npmjs.com/package/busboy) package |
9 | 10 | */
|
10 |
| -private class BusBoyRemoteFlow extends RemoteFlowSource { |
11 |
| - BusBoyRemoteFlow() { |
12 |
| - this = |
13 |
| - API::moduleImport("busboy") |
14 |
| - .getInstance() |
15 |
| - .getMember("on") |
16 |
| - .getParameter(1) |
17 |
| - .getAParameter() |
18 |
| - .asSource() |
| 11 | +module BusBoy { |
| 12 | + /** |
| 13 | + * A source of remote flow from the `Busboy` library. |
| 14 | + */ |
| 15 | + private class BusBoyRemoteFlow extends RemoteFlowSource { |
| 16 | + BusBoyRemoteFlow() { |
| 17 | + exists(API::Node busboyOnEvent | |
| 18 | + busboyOnEvent = API::moduleImport("busboy").getReturn().getMember("on") |
| 19 | + | |
| 20 | + // Files |
| 21 | + busboyOnEvent.getParameter(0).asSink().mayHaveStringValue("file") and |
| 22 | + // second param of 'file' event is a Readable stream |
| 23 | + this = readableStreamDataNode(busboyOnEvent.getParameter(1).getParameter(1)).asSource() |
| 24 | + or |
| 25 | + // Fields |
| 26 | + busboyOnEvent.getParameter(0).asSink().mayHaveStringValue(["file", "field"]) and |
| 27 | + this = |
| 28 | + API::moduleImport("busboy") |
| 29 | + .getReturn() |
| 30 | + .getMember("on") |
| 31 | + .getParameter(1) |
| 32 | + .getAParameter() |
| 33 | + .asSource() |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + override string getSourceType() { result = "parsed user value from Busbuy" } |
19 | 38 | }
|
20 | 39 |
|
21 |
| - override string getSourceType() { result = "parsed user value from Busbuy" } |
| 40 | + /** |
| 41 | + * Holds if busboy file data as additional taint steps according to a Readable Stream type |
| 42 | + * |
| 43 | + * TODO: I don't know how it can be a global taint step! |
| 44 | + */ |
| 45 | + predicate busBoyReadableAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) { |
| 46 | + exists(API::Node busboyOnEvent | |
| 47 | + busboyOnEvent = API::moduleImport("busboy").getReturn().getMember("on") |
| 48 | + | |
| 49 | + busboyOnEvent.getParameter(0).asSink().mayHaveStringValue("file") and |
| 50 | + customStreamPipeAdditionalTaintStep(busboyOnEvent.getParameter(1).getParameter(1), pred, succ) |
| 51 | + ) |
| 52 | + } |
22 | 53 | }
|
23 | 54 |
|
24 | 55 | /**
|
25 |
| - * A source of remote flow from the `Formidable` library parsing a HTTP request. |
| 56 | + * A module for modeling [formidable](https://www.npmjs.com/package/formidable) package |
26 | 57 | */
|
27 |
| -private class FormidableRemoteFlow extends RemoteFlowSource { |
28 |
| - FormidableRemoteFlow() { |
29 |
| - exists(API::Node formidable | |
30 |
| - formidable = API::moduleImport("formidable").getReturn() |
31 |
| - or |
32 |
| - formidable = API::moduleImport("formidable").getMember("formidable").getReturn() |
33 |
| - or |
34 |
| - formidable = |
35 |
| - API::moduleImport("formidable").getMember(["IncomingForm", "Formidable"]).getInstance() |
36 |
| - | |
37 |
| - this = |
38 |
| - formidable.getMember("parse").getACall().getABoundCallbackParameter(1, any(int i | i > 0)) |
39 |
| - ) |
| 58 | +module Formidable { |
| 59 | + /** |
| 60 | + * A source of remote flow from the `Formidable` library parsing a HTTP request. |
| 61 | + */ |
| 62 | + private class FormidableRemoteFlow extends RemoteFlowSource { |
| 63 | + FormidableRemoteFlow() { |
| 64 | + exists(API::Node formidable | |
| 65 | + formidable = API::moduleImport("formidable").getReturn() |
| 66 | + or |
| 67 | + formidable = API::moduleImport("formidable").getMember("formidable").getReturn() |
| 68 | + or |
| 69 | + formidable = |
| 70 | + API::moduleImport("formidable").getMember(["IncomingForm", "Formidable"]).getInstance() |
| 71 | + | |
| 72 | + this = |
| 73 | + formidable.getMember("parse").getACall().getABoundCallbackParameter(1, any(int i | i > 0)) |
| 74 | + or |
| 75 | + // if callback is not provide a promise will be returned, |
| 76 | + // return values contains [fields,files] members |
| 77 | + exists(API::Node parseMethod | |
| 78 | + parseMethod = formidable.getMember("parse") and parseMethod.getNumParameter() = 1 |
| 79 | + | |
| 80 | + this = parseMethod.getReturn().asSource() |
| 81 | + ) |
| 82 | + or |
| 83 | + // event handler |
| 84 | + this = formidable.getMember("on").getParameter(1).getAParameter().asSource() |
| 85 | + ) |
| 86 | + } |
| 87 | + |
| 88 | + override string getSourceType() { result = "parsed user value from Formidable" } |
40 | 89 | }
|
| 90 | +} |
41 | 91 |
|
42 |
| - override string getSourceType() { result = "parsed user value from Formidable" } |
| 92 | +API::Node test() { |
| 93 | + result = |
| 94 | + API::moduleImport("multiparty").getMember("Form").getInstance().getMember("on").getASuccessor*() |
43 | 95 | }
|
44 | 96 |
|
45 | 97 | /**
|
46 |
| - * A source of remote flow from the `Multiparty` library. |
| 98 | + * A module for modeling [multiparty](https://www.npmjs.com/package/multiparty) package |
47 | 99 | */
|
48 |
| -private class MultipartyRemoteFlow extends RemoteFlowSource { |
49 |
| - MultipartyRemoteFlow() { |
50 |
| - exists(API::Node form | form = API::moduleImport("multiparty").getMember("Form").getInstance() | |
51 |
| - exists(API::CallNode parse | parse = form.getMember("parse").getACall() | |
52 |
| - this = parse.getParameter(1).getAParameter().asSource() |
| 100 | +module Multiparty { |
| 101 | + /** |
| 102 | + * A source of remote flow from the `Multiparty` library. |
| 103 | + */ |
| 104 | + private class MultipartyRemoteFlow extends RemoteFlowSource { |
| 105 | + MultipartyRemoteFlow() { |
| 106 | + exists(API::Node form | |
| 107 | + form = API::moduleImport("multiparty").getMember("Form").getInstance() |
| 108 | + | |
| 109 | + exists(API::CallNode parse | parse = form.getMember("parse").getACall() | |
| 110 | + this = parse.getParameter(1).getParameter([1, 2]).asSource() |
| 111 | + ) |
| 112 | + or |
| 113 | + exists(API::Node on | on = form.getMember("on") | |
| 114 | + ( |
| 115 | + on.getParameter(0).asSink().mayHaveStringValue(["file", "field"]) and |
| 116 | + this = on.getParameter(1).getParameter([0, 1]).asSource() |
| 117 | + or |
| 118 | + on.getParameter(0).asSink().mayHaveStringValue("part") and |
| 119 | + this = readableStreamDataNode(on.getParameter(1).getParameter(0)).asSink() |
| 120 | + ) |
| 121 | + ) |
53 | 122 | )
|
54 |
| - or |
55 |
| - exists(API::CallNode on | on = form.getMember("on").getACall() | |
56 |
| - on.getArgument(0).mayHaveStringValue(["part", "file", "field"]) and |
57 |
| - this = on.getParameter(1).getAParameter().asSource() |
58 |
| - ) |
59 |
| - ) |
| 123 | + } |
| 124 | + |
| 125 | + override string getSourceType() { result = "parsed user value from Multiparty" } |
60 | 126 | }
|
61 | 127 |
|
62 |
| - override string getSourceType() { result = "parsed user value from Multiparty" } |
| 128 | + /** |
| 129 | + * Holds if multiparty part data as additional taint steps according to a Readable Stream type |
| 130 | + * |
| 131 | + * TODO: I don't know how it can be a global taint step! |
| 132 | + */ |
| 133 | + predicate multipartyReadableAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) { |
| 134 | + exists(API::Node multipartyOnEvent | |
| 135 | + multipartyOnEvent = |
| 136 | + API::moduleImport("multiparty").getMember("Form").getInstance().getMember("on") |
| 137 | + | |
| 138 | + multipartyOnEvent.getParameter(0).asSink().mayHaveStringValue("part") and |
| 139 | + customStreamPipeAdditionalTaintStep(multipartyOnEvent.getParameter(1).getParameter(0), pred, |
| 140 | + succ) |
| 141 | + ) |
| 142 | + } |
63 | 143 | }
|
0 commit comments