Skip to content
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

Bugfix issue 27877 jwt token with space is valid #28678

Conversation

danieldradware
Copy link
Contributor

@danieldradware danieldradware commented Jul 28, 2023

…non base64 characters

Commit Message:
This PR should fix issue #27877
Additional Description:
New behavior isn't cutting characters after non base64 character
Now expected to get all token and then mark it as invalid jwt
All details in issue #27877
Risk Level:
Medium
Testing:
Added unit test
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
Fixes #27877
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

@yanavlasov
Copy link
Contributor

/wait

return value_str.substr(starting);
}
return value_str.substr(starting, ending - starting);
return value_str.substr(starting);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a runtime guard warranted for this change? https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md#runtime-guarding

Generally as a community we try to guard [...] most user-visible non-config-guarded changes to protocol processing (for example additions or changes to HTTP headers or how HTTP is serialized out) for non-alpha features. Feel free to tag @envoyproxy/maintainers if you aren't sure if a given change merits runtime guarding.

I'm slightly worried it will break runtime traffic for clients using it (https://www.hyrumslaw.com/). Though this is a very unique corner case and I doubt clients rely on this behavior. Either way, worth asking @envoyproxy/maintainers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RFC 7519 implies that adding non-Base64URL characters after a valid JWT token makes it invalid. Thus, if a the JWT is followed by a space and some Base64URL characters or just followed by non Base64URL characters like ### (without any space) it should be considered invalid.

Copy link
Contributor

Choose a reason for hiding this comment

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

@danieldradware we agree with you that the current behavior is a bug. However there could be Envoy users who relied on this buggy behavior and if we just change it it will affect their system. To prevent this we add runtime override that would bring back old behavior. In 6 months this override is removed.

It is not very hard to add a runtime override. Please see PR #27974 for example.

@danieldradware danieldradware force-pushed the issue-25239-jwt-authn-filter-is-pass-invalid-authorization-bearer branch 2 times, most recently from a86086f to 0c37cbf Compare August 1, 2023 10:22
@danieldradware danieldradware force-pushed the issue-25239-jwt-authn-filter-is-pass-invalid-authorization-bearer branch 2 times, most recently from feb3a6f to 0ed9834 Compare August 9, 2023 16:29
@danieldradware
Copy link
Contributor Author

Hi @yanavlasov
CI is pass, someone can review it?
Thanks in advance
Daniel

@yanavlasov yanavlasov self-assigned this Aug 15, 2023
Copy link
Contributor

@yanavlasov yanavlasov left a comment

Choose a reason for hiding this comment

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

/wait

return value_str.substr(starting);
}
return value_str.substr(starting, ending - starting);
return value_str.substr(starting);
Copy link
Contributor

Choose a reason for hiding this comment

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

@danieldradware we agree with you that the current behavior is a bug. However there could be Envoy users who relied on this buggy behavior and if we just change it it will affect their system. To prevent this we add runtime override that would bring back old behavior. In 6 months this override is removed.

It is not very hard to add a runtime override. Please see PR #27974 for example.

@repokitteh-read-only
Copy link

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #28678 was synchronize by danieldradware.

see: more, trace.

@danieldradware danieldradware force-pushed the issue-25239-jwt-authn-filter-is-pass-invalid-authorization-bearer branch from 5e0be3c to 3ac8ab9 Compare August 17, 2023 05:31
@yanavlasov
Copy link
Contributor

@danieldradware the runtime features require alphanumeric order

ERROR: From ./source/common/runtime/runtime_features.cc
ERROR: RUNTIME_GUARD(envoy_reloadable_features_http_reject_path_with_fragment); and RUNTIME_GUARD(envoy_reloadable_features_token_passed_entirely); are out of order

@yanavlasov
Copy link
Contributor

Can you also add a test that check the behavior with the envoy.reloadable_features.token_passed_entirely == false, please? In this was it is certain that old behavior is still working with override. Look good otherwise.

/wait

@danieldradware danieldradware force-pushed the issue-25239-jwt-authn-filter-is-pass-invalid-authorization-bearer branch from ced687c to ba5972b Compare August 22, 2023 14:37
…non base64 characters

Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
…(dis)

Signed-off-by: danield <danield@radware.com>
@phlax
Copy link
Member

phlax commented Aug 29, 2023

@yanavlasov i think this is waiting on further review

/wait-any

Signed-off-by: danield <danield@radware.com>
danieldradware and others added 7 commits August 29, 2023 17:54
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
Signed-off-by: danield <danield@radware.com>
@danieldradware
Copy link
Contributor Author

Hi @yanavlasov @phlax
I saw there is a failure in pipeline cause network issue,
Can you please rerun only specific jobs that failures?
Thanks!

@danieldradware
Copy link
Contributor Author

Hi @yanavlasov @phlax I saw there is a failure in pipeline cause network issue, Can you please rerun only specific jobs that failures? Thanks!

Thanks for rerun it.
Can you please approve the PR and merge it with main?

Copy link
Contributor

@yanavlasov yanavlasov left a comment

Choose a reason for hiding this comment

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

/wait

RUNTIME_GUARD(envoy_reloadable_features_uhv_allow_malformed_url_encoding);
RUNTIME_GUARD(envoy_reloadable_features_uhv_preserve_url_encoded_case);
Copy link
Contributor

Choose a reason for hiding this comment

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

These runtime keys looks like result of a bad merge. Please remove them, since they are not part of this change.

@yanavlasov
Copy link
Contributor

I was also looking for a test with the following in it:

      TestScopedRuntime scoped_runtime;
      scoped_runtime.mergeValues({{"envoy.reloadable_features.token_passed_entirely", "false"}});

that tests old behavior. Can you add a test like this please?

@danieldradware
Copy link
Contributor Author

I was also looking for a test with the following in it:

      TestScopedRuntime scoped_runtime;
      scoped_runtime.mergeValues({{"envoy.reloadable_features.token_passed_entirely", "false"}});

that tests old behavior. Can you add a test like this please?

Hi @yanavlasov
Sure I already added unit test to test the old behavior, you can see it at:test/extensions/filters/http/jwt_authn/extractor_runtime_guard_test.cc and BUILD file that contain: args = ["--runtime-feature-disable-for-tests=envoy.reloadable_features.token_passed_entirely"],

removed RUNTIME_GUARD(envoy_reloadable_features_uhv_preserve_url_encoded_case);

Signed-off-by: danieldradware <117576776+danieldradware@users.noreply.github.com>
@danieldradware
Copy link
Contributor Author

Can you please rerun Linux arm64 section?
Thanks!

@zirain
Copy link
Contributor

zirain commented Sep 3, 2023

/retest

@danieldradware
Copy link
Contributor Author

Hi @yanavlasov
Can you please remove "change requested" action? (I already pushed all changed you asked from me).

BTW who can give to this PR an approval?

Thanks a lot
Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants