screwdriver-api 8.0.52 → 8.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "8.0.52",
3
+ "version": "8.0.53",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -86,9 +86,11 @@ const webhooksPlugin = {
86
86
  }
87
87
 
88
88
  let size = 0;
89
+ let data = '';
89
90
 
90
91
  for await (const chunk of request.payload) {
91
92
  size += chunk.length;
93
+ data += chunk;
92
94
  if (size > (webhookSettings.maxBytes || DEFAULT_MAX_BYTES)) {
93
95
  throw boom.entityTooLarge(
94
96
  `Payload size exceeds the maximum limit of ${webhookSettings.maxBytes || DEFAULT_MAX_BYTES} bytes`
@@ -96,7 +98,15 @@ const webhooksPlugin = {
96
98
  }
97
99
  }
98
100
 
99
- const parsed = await scm.parseHook(request.headers, request.payload);
101
+ let parsedPayload;
102
+
103
+ try {
104
+ parsedPayload = JSON.parse(data);
105
+ } catch (err) {
106
+ throw boom.badData('Cannot parse payload');
107
+ }
108
+
109
+ const parsed = await scm.parseHook(request.headers, parsedPayload);
100
110
 
101
111
  if (!parsed) {
102
112
  // for all non-matching events or actions