Skip to content

Commit 8a50f81

Browse files
authored
Upgrade @hapi/hoek to revert hack introduced in hapi v20 upgrade (#87113) (#87130)
1 parent ec7ed6a commit 8a50f81

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"@hapi/good-squeeze": "6.0.0",
114114
"@hapi/h2o2": "^9.0.2",
115115
"@hapi/hapi": "^20.0.3",
116-
"@hapi/hoek": "^9.1.0",
116+
"@hapi/hoek": "^9.1.1",
117117
"@hapi/inert": "^6.0.3",
118118
"@hapi/podium": "^4.1.1",
119119
"@hapi/statehood": "^7.0.3",

src/core/server/http/http_server.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { Server, ServerRoute } from '@hapi/hapi';
19+
import { Server } from '@hapi/hapi';
2020
import HapiStaticFiles from '@hapi/inert';
2121
import url from 'url';
2222
import uuid from 'uuid';
@@ -167,21 +167,28 @@ export class HttpServer {
167167
for (const router of this.registeredRouters) {
168168
for (const route of router.getRoutes()) {
169169
this.log.debug(`registering route handler for [${route.path}]`);
170+
// Hapi does not allow payload validation to be specified for 'head' or 'get' requests
171+
const validate = isSafeMethod(route.method) ? undefined : { payload: true };
170172
const { authRequired, tags, body = {}, timeout } = route.options;
171173
const { accepts: allow, maxBytes, output, parse } = body;
172174

173175
const kibanaRouteOptions: KibanaRouteOptions = {
174176
xsrfRequired: route.options.xsrfRequired ?? !isSafeMethod(route.method),
175177
};
176178

177-
const routeOpts: ServerRoute = {
179+
this.server.route({
178180
handler: route.handler,
179181
method: route.method,
180182
path: route.path,
181183
options: {
182184
auth: this.getAuthOption(authRequired),
183185
app: kibanaRouteOptions,
184186
tags: tags ? Array.from(tags) : undefined,
187+
// TODO: This 'validate' section can be removed once the legacy platform is completely removed.
188+
// We are telling Hapi that NP routes can accept any payload, so that it can bypass the default
189+
// validation applied in ./http_tools#getServerOptions
190+
// (All NP routes are already required to specify their own validation in order to access the payload)
191+
validate,
185192
// @ts-expect-error Types are outdated and doesn't allow `payload.multipart` to be `true`
186193
payload: [allow, maxBytes, output, parse, timeout?.payload].some((x) => x !== undefined)
187194
? {
@@ -197,22 +204,7 @@ export class HttpServer {
197204
socket: timeout?.idleSocket ?? this.config!.socketTimeout,
198205
},
199206
},
200-
};
201-
202-
// Hapi does not allow payload validation to be specified for 'head' or 'get' requests
203-
if (!isSafeMethod(route.method)) {
204-
// TODO: This 'validate' section can be removed once the legacy platform is completely removed.
205-
// We are telling Hapi that NP routes can accept any payload, so that it can bypass the default
206-
// validation applied in ./http_tools#getServerOptions
207-
// (All NP routes are already required to specify their own validation in order to access the payload)
208-
// TODO: Move the setting of the validate option back up to being set at `routeOpts` creation-time once
209-
// https://github.com/hapijs/hoek/pull/365 is merged and released in @hapi/hoek v9.1.1. At that point I
210-
// imagine the ts-error below will go away as well.
211-
// @ts-expect-error "Property 'validate' does not exist on type 'RouteOptions'" <-- ehh?!? yes it does!
212-
routeOpts.options!.validate = { payload: true };
213-
}
214-
215-
this.server.route(routeOpts);
207+
});
216208
}
217209
}
218210

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,10 +1970,10 @@
19701970
"@hapi/hoek" "9.x.x"
19711971
"@hapi/validate" "1.x.x"
19721972

1973-
"@hapi/hoek@9.x.x", "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.0.4", "@hapi/hoek@^9.1.0":
1974-
version "9.1.0"
1975-
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.1.0.tgz#6c9eafc78c1529248f8f4d92b0799a712b6052c6"
1976-
integrity sha512-i9YbZPN3QgfighY/1X1Pu118VUz2Fmmhd6b2n0/O8YVgGGfw0FbUYoA97k7FkpGJ+pLCFEDLUmAPPV4D1kpeFw==
1973+
"@hapi/hoek@9.x.x", "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.0.4", "@hapi/hoek@^9.1.1":
1974+
version "9.1.1"
1975+
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.1.1.tgz#9daf5745156fd84b8e9889a2dc721f0c58e894aa"
1976+
integrity sha512-CAEbWH7OIur6jEOzaai83jq3FmKmv4PmX1JYfs9IrYcGEVI/lyL1EXJGCj7eFVJ0bg5QR8LMxBlEtA+xKiLpFw==
19771977

19781978
"@hapi/inert@^6.0.3":
19791979
version "6.0.3"

0 commit comments

Comments
 (0)