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

SQL persister uses | to store scopes and audiences without any escaping #2859

Closed
4 of 6 tasks
mitar opened this issue Nov 15, 2021 · 4 comments
Closed
4 of 6 tasks

SQL persister uses | to store scopes and audiences without any escaping #2859

mitar opened this issue Nov 15, 2021 · 4 comments
Assignees
Labels
bug Something is not working.
Milestone

Comments

@mitar
Copy link
Contributor

mitar commented Nov 15, 2021

Preflight checklist

Describe the bug

See here:

		Scopes:            strings.Join(r.GetRequestedScopes(), "|"),
		GrantedScope:      strings.Join(r.GetGrantedScopes(), "|"),
		GrantedAudience:   strings.Join(r.GetGrantedAudience(), "|"),
		RequestedAudience: strings.Join(r.GetRequestedAudience(), "|"),

| is not a reserved character in any way and could happen to be included inside scopes and audiences. This means that if any legitimate scope contains | character (e.g., user|mails|read), this will break. I have not seen this character be used like that in scopes (generally people use : or / or .) but still, I think it is unnecessary potential issue. If you want to use this custom encoding of a list (and not use JSON or something), then you have to escape | inside scopes and audiences.

On the other hand, (space) cannot happen to be in scopes or audiences, because it is a reserved character by the spec itself, so I would suggest that this is simple replaced with as delimiter.

Reproducing the bug

This was found during code review.

Relevant log output

No response

Relevant configuration

No response

Version

observed on current master branch

On which operating system are you observing this issue?

No response

In which environment are you deploying?

No response

Additional Context

No response

@mitar mitar added the bug Something is not working. label Nov 15, 2021
@aeneasr
Copy link
Member

aeneasr commented Nov 15, 2021

Good point and thank you for the thorough review! I'd like to add though that spaces are reserved (iirc) for scope but are not reserved in other parts. aud (a JWT claim) is StringOrURI which does not have a distinguished character set - it's a plain string:

StringOrURI
A JSON string value, with the additional requirement that while
arbitrary string values MAY be used, any value containing a ":"
character MUST be a URI [RFC3986]. StringOrURI values are
compared as case-sensitive strings with no transformations or
canonicalizations applied. (Source)

Thus, | should indeed be escaped. Changing delimiter is, IMO, not possible without tons and tons of work. As this has never been reported as a bug since the project's inception, I'd prefer to escape vs refactor as it doesn't seem that anyone is affected by this behaviour at the moment!

Contribs welcomed :)

@mitar mitar mentioned this issue Nov 23, 2021
6 tasks
@aeneasr
Copy link
Member

aeneasr commented Jan 11, 2022

@grantzvolsky we have changed this to a different method which now uses JSON for these types of arrays. The relevant type is this one: https://github.com/ory/x/blob/7112e2632340e269159c73b5ebde8149374aecea/sqlxx/types.go#L267

Maybe it makes sense as part of Hydra 2.0 to address this since we're changing the schema anyways?

@aeneasr
Copy link
Member

aeneasr commented Jan 11, 2022

I have code that helps you convert the piped version to a JSON array literal. I can show you when you take a look at this.

@aeneasr aeneasr added this to the v2.0 milestone Jan 19, 2022
@grantzvolsky
Copy link
Contributor

@aeneasr I'll keep this in mind and let you know when I need it. Thanks!

@aeneasr aeneasr closed this as completed May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
Development

No branches or pull requests

3 participants