Skip to content

fix: Update persister_oauth2.go to handle special character | coming in t… #3849

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Ajayn84
Copy link

@Ajayn84 Ajayn84 commented Sep 25, 2024

…he scopes as part of consent request

Url encoded and decoded while fetching values from the table, as "|" is a seperator used to store scopes

Related issue(s)

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got the approval (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

…e scopes as part of consent request

Url encoded and decoded while fetching values from the table,  as "|" is a seperator used to store scopes
@CLAassistant
Copy link

CLAassistant commented Sep 25, 2024

CLA assistant check
All committers have signed the CLA.

@Ajayn84 Ajayn84 changed the title Update persister_oauth2.go to handle special character | coming in t… Fix:Update persister_oauth2.go to handle special character | coming in t… Sep 25, 2024
@Ajayn84 Ajayn84 changed the title Fix:Update persister_oauth2.go to handle special character | coming in t… fix:Update persister_oauth2.go to handle special character | coming in t… Sep 25, 2024
@Ajayn84 Ajayn84 changed the title fix:Update persister_oauth2.go to handle special character | coming in t… fix: Update persister_oauth2.go to handle special character | coming in t… Sep 25, 2024
@Ajayn84
Copy link
Author

Ajayn84 commented Dec 2, 2024

@hperl @aeneasr @alnr request your reviews

@Ajayn84 Ajayn84 changed the title fix: Update persister_oauth2.go to handle special character | coming in t… fix: Update persister_oauth2.go to handle special character | coming in t… (https://github.com/ory/hydra/issues/3829) Dec 2, 2024
@Ajayn84 Ajayn84 changed the title fix: Update persister_oauth2.go to handle special character | coming in t… (https://github.com/ory/hydra/issues/3829) fix: Update persister_oauth2.go to handle special character | coming in t… Dec 2, 2024
@Ajayn84
Copy link
Author

Ajayn84 commented Dec 2, 2024

Links to #3829

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

This is a backwards incompatible change that will break all existing rows. I don't think there's appetite to fix this at the moment and the solution would need to be backwards compatible and well-tested. It's probably easier to just adjust the scope charset

@Ajayn84
Copy link
Author

Ajayn84 commented Jan 30, 2025

t's probably easier to just adjust the scope charset

@aeneasr can you please elaborate, i did try to encode , but since this logic is more controlled in the Hydra, it just took that param as "%7C" and responded with scopes having "%7C" instead of "|"

We cant replace the | (pipe) char ,as its a requirement from Hl7 Smart App launch https://www.hl7.org/fhir/smart-app-launch/scopes-and-launch-context.html#finer-grained-resource-constraints-using-search-parameters

Were you suggesting some other way to fix this issue?
Also, dont think the current scopes with "|" will be working anyways, so dont think this should have backward compatibility issues

@@ -118,8 +118,8 @@ func (p *Persister) sqlSchemaFromRequest(ctx context.Context, signature string,
RequestedAt: r.GetRequestedAt(),
InternalExpiresAt: sqlxx.NullTime(expiresAt),
Client: r.GetClient().GetID(),
Scopes: strings.Join(r.GetRequestedScopes(), "|"),
GrantedScope: strings.Join(r.GetGrantedScopes(), "|"),
Scopes: strings.Join(escapeDelimiter(r.GetRequestedScopes()), "|"),
Copy link
Author

Choose a reason for hiding this comment

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

we are escaping delimter "|" using queryescape and then joining with "|" delimiter, so that scopes with "|" are replaced with and then joined using "|"

return &fosite.Request{
ID: r.Request,
RequestedAt: r.RequestedAt,
// ExpiresAt does not need to be populated as we get the expiry time from the session.
Client: c,
RequestedScope: stringsx.Splitx(r.Scopes, "|"),
GrantedScope: stringsx.Splitx(r.GrantedScope, "|"),
RequestedScope: scopes,
Copy link
Author

Choose a reason for hiding this comment

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

we are splitting the data from db with "|" and then unescaping to get "|" back in the scopes if any

@sagarshah1983
Copy link
Contributor

@Ajayn84 Have you found a workaround with this? We are also facing the same issue for same SMART on FHIR implementation.

@aeneasr - Could you please share the other suggestion that you may have on how to go about fixing this in hydra?

@aeneasr
Copy link
Member

aeneasr commented Feb 9, 2025

Hello, we already have methods to properly delimit string arrays using JSON encoding if I'm not mistaken in our sqlxx package. However, changing the way these things are parsed is a breaking change and requires a careful migration path as it can break all existing records. Given the risk associated, we just ask you to use a different delimiter in scopes.

Furthermore, | is not a valid url character and would need to be url-en/decoded in URLs, which makes it not that great of an option for use in the scope field, further reducing the likelihood of getting this merged.

@Ajayn84
Copy link
Author

Ajayn84 commented Feb 10, 2025

We cant replace the "|" pipe char with other char, as its a regulatory ask in healthcare. Hl7 Smart App launch link where it indicates the same https://www.hl7.org/fhir/smart-app-launch/scopes-and-launch-context.html#finer-grained-resource-constraints-using-search-parameters

@Ajayn84
Copy link
Author

Ajayn84 commented Feb 10, 2025

@Ajayn84 Have you found a workaround with this? We are also facing the same issue for same SMART on FHIR implementation.

@aeneasr - Could you please share the other suggestion that you may have on how to go about fixing this in hydra?

No @sagarshah1983 , we are also trying to implement Smart on FHIR and specs indicate use of "|" in scopes, without a workaround

@aeneasr
Copy link
Member

aeneasr commented Feb 10, 2025

Thank you for pointing me to the spec - in that case the use case is legitimate in my view. Still, it's not trivial to implement this and if we fix it it should be a long-term solution (i.e. using the appropriate data types). I will synchronize with @vinckr to figure out what to best do here as I'm actually PTO :)

@Ajayn84
Copy link
Author

Ajayn84 commented Feb 10, 2025

Thank you for pointing me to the spec - in that case the use case is legitimate in my view. Still, it's not trivial to implement this and if we fix it it should be a long-term solution (i.e. using the appropriate data types). I will synchronize with @vinckr to figure out what to best do here as I'm actually PTO :)

Thanks @aeneasr.

@vinckr
Copy link
Member

vinckr commented Feb 10, 2025

@Ajayn84
can you write me an email at [email protected] to discuss the options further please?

@Ajayn84
Copy link
Author

Ajayn84 commented Feb 11, 2025

@Ajayn84 can you write me an email at [email protected] to discuss the options further please?

Sure @vinckr

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

Successfully merging this pull request may close these issues.

5 participants