Skip to content

Assert that REST params are consumed iff supported #113933

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

Conversation

DaveCTurner
Copy link
Contributor

@DaveCTurner DaveCTurner commented Oct 2, 2024

REST APIs which declare their supported parameters must consume exactly
those parameters: consuming an unsupported parameter means that requests
including that parameter will be rejected, whereas failing to consume a
supported parameter means that this parameter has no effect and should
be removed.

This commit adds an assertion to verify that we are consuming the
correct parameters.

Closes #113854

@DaveCTurner DaveCTurner added >test Issues or PRs that are addressing/adding tests :Core/Infra/REST API REST infrastructure and utilities v8.16.0 v9.0.0 labels Oct 2, 2024
@DaveCTurner DaveCTurner force-pushed the 2024/10/02/ensure-consumed-params-supported branch from f9844df to 2902035 Compare October 2, 2024 10:57
@DaveCTurner DaveCTurner changed the title Assert that consumed REST params are supported Assert that REST params are consumed iff supported Oct 2, 2024
REST APIs which declare their supported parameters must consume exactly
those parameters: consuming an unsupported parameter means that requests
including that parameter will be rejected, whereas failing to consume a
supported parameter means that this parameter has no effect and should
be removed.

This commit adds an assertion to verify that we are consuming the
correct parameters.

Closes elastic#113854
@DaveCTurner DaveCTurner force-pushed the 2024/10/02/ensure-consumed-params-supported branch from 6c6e45e to e33234e Compare October 2, 2024 12:22
@DaveCTurner DaveCTurner marked this pull request as ready for review October 2, 2024 12:23
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Oct 2, 2024
@DaveCTurner DaveCTurner requested review from rjernst and a team October 2, 2024 12:23
private boolean assertConsumesSupportedParams(@Nullable Set<String> supported, RestRequest request) {
if (supported != null) {
final var supportedAndCommon = new TreeSet<>(supported);
supportedAndCommon.addAll(List.of("error_trace", "filter_path", "format", "pretty", "human"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have these common params defined anywhere so this isn't an arbitrary list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh not all of them. There's org.elasticsearch.rest.BaseRestHandler#ALWAYS_SUPPORTED but that doesn't include error_trace. I pushed a commit that uses ALWAYS_SUPPORTED. Not a huge deal here in any case, if we get this wrong then this assertion will trip.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DaveCTurner DaveCTurner merged commit 6d7ae82 into elastic:main Oct 3, 2024
16 checks passed
@DaveCTurner DaveCTurner deleted the 2024/10/02/ensure-consumed-params-supported branch October 3, 2024 05:44
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 113933

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Oct 3, 2024
REST APIs which declare their supported parameters must consume exactly
those parameters: consuming an unsupported parameter means that requests
including that parameter will be rejected, whereas failing to consume a
supported parameter means that this parameter has no effect and should
be removed.

This commit adds an assertion to verify that we are consuming the
correct parameters.

Closes elastic#113854
Backport of elastic#113933 to `8.x`
gmarouli pushed a commit to gmarouli/elasticsearch that referenced this pull request Oct 3, 2024
REST APIs which declare their supported parameters must consume exactly
those parameters: consuming an unsupported parameter means that requests
including that parameter will be rejected, whereas failing to consume a
supported parameter means that this parameter has no effect and should
be removed.

This commit adds an assertion to verify that we are consuming the
correct parameters.

Closes elastic#113854
DaveCTurner added a commit that referenced this pull request Oct 3, 2024
@DaveCTurner
Copy link
Contributor Author

Bah this had a bug, I reverted it and will open a fresh PR.

matthewabbott pushed a commit to matthewabbott/elasticsearch that referenced this pull request Oct 4, 2024
REST APIs which declare their supported parameters must consume exactly
those parameters: consuming an unsupported parameter means that requests
including that parameter will be rejected, whereas failing to consume a
supported parameter means that this parameter has no effect and should
be removed.

This commit adds an assertion to verify that we are consuming the
correct parameters.

Closes elastic#113854
matthewabbott pushed a commit to matthewabbott/elasticsearch that referenced this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/REST API REST infrastructure and utilities Team:Core/Infra Meta label for core/infra team >test Issues or PRs that are addressing/adding tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forbid consumption of unsupported query params
3 participants