-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle path param validation regexes for undertow handlers #2119
base: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
3ae36ed
to
bde7260
Compare
@@ -329,7 +336,7 @@ private TypeSpec generateEndpointHandler( | |||
.addModifiers(Modifier.PUBLIC) | |||
.addAnnotation(Override.class) | |||
.returns(String.class) | |||
.addStatement("return $1S", endpointDefinition.getHttpPath()) | |||
.addStatement("return $1S", normalizeHttpPathTemplates(endpointDefinition.getHttpPath())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual code change.
At a high level, I think it would be better to fail fast if an input isn't fully supported rather than producing slightly unexpected behavior at runtime -- I could imagine a scenario where the path regex is used for security, perhaps to prevent certain path traversal attacks, where passing through the raw value may not be great. I think the malformed name including regex will not work, but currently I expect it fails consistently. I would be in favor of causing the generator to fail eagerly when these patterns are detected. I thought we had officially deprecated the regex-in-pathparm feature, but perhaps that was never messaged out in the spec -- it was an intentional change not to support path param regex. We could write our own RoutingHandler which understands these patterns if the lack of support is causing problems |
Makes sense! There are a few usages, but I think those only use Jersey endpoints or would otherwise have broken endpoints anyway. Can update the PR to fail Undertow generation when encountering these cases later! |
Before this PR
The Conjure spec technically allows simple regex validations in http path parameters such as
/foo/{bar:.+}
(see palantir/conjure#297, code). However, when used to generate an Undertow endpoint handler, those would result in runtime errors when trying to access the path param.Currently, an Undertow handler would look something like this:
Notice how it uses
pathParams.get("param")
while the path template still contains the regex validation. The template gets passed to undertow'sPathTemplate
, which doesn't support regex validations and instead handles the entireparam:.+
as the parameter name.At runtime, this will result in an invalid argument exception, due to the requested parameter
param
being null (see test: 4610af8).After this PR
This PR adds a naive fix of ignoring path param validation regexes when generating Undertow handlers but I'm not sure if that's the best path forward.
If we don't want to support those validations, we could still allow them in the spec but drop them much earlier when parsing into endpoint definitions? There are a few usages in conjure definitions in the wild, so we can't drop them from the spec without a break.
==COMMIT_MSG==
Handle path param validation regexes for undertow handlers
==COMMIT_MSG==
Possible downsides?