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

Usernames and passwords in connection strings aren't escaped #3117

Open
DamianEdwards opened this issue Mar 23, 2024 · 14 comments
Open

Usernames and passwords in connection strings aren't escaped #3117

DamianEdwards opened this issue Mar 23, 2024 · 14 comments
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Milestone

Comments

@DamianEdwards
Copy link
Member

While investigating #2247 I used a parameter to create a stable password for a RabbitMQ resource, only to find that the password I'd generated contained a character that broke the connection string. RabbitMQ connection strings are actually URIs, so if the username or password contains restricted characters (e.g. @) then the RabbitMQ client fails due to the URI being invalid.

I updated ReferenceExpression to support custom value escaping and a convenience method for getting a URI escaped version of an existing ReferenceExpression and that solves the issue for runtime, but this issue will occur during manifest processing too. Resolving that is a much bigger challenge that will need some thought.

@DamianEdwards DamianEdwards added bug area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication labels Mar 23, 2024
@DamianEdwards DamianEdwards changed the title Usernames and passwords in connection strings need to be escaped Usernames and passwords in connection strings aren't escaped Mar 23, 2024
DamianEdwards added a commit that referenced this issue Mar 23, 2024
WIP
Contributes to #2247
Contributes to #3117
@eerhardt
Copy link
Member

I think in order to be able to solve this generically, and in all the places we need to fix it, we will need to:

  1. Have a set of "well known" escape strategies/algorithms.
  2. Encode which escape strategy to use inside the ReferenceExpression, so it gets written to the manifest.

RabbitMQ uses URIs, but PostgreSQL uses DbConnectionString. To properly escape any string in a DbConnectionString, we would need to add single quotes ' around the value, and then escape any real single quotes in the value by doubling them: ''.

So at a minimum we would need 2 strategies: URI escaping and single-quote escaping.

As you pointed out above, we would need to put this in the manifest and have any deployment tools (like azd) understand these strategies.

cc @davidfowl @mitchdenny @ellismg @vhvb1989

@DamianEdwards
Copy link
Member Author

So we'd represent this in the manifest something like this?
"amqp://{urlencode(resources.rabbitusr.value)}:{urlencode(resources.rabbitpw.value)}@{resources.rabbitmq.bindings.tcp.host}:{resources.rabbitmq.bindings.tcp.port}"

DamianEdwards added a commit that referenced this issue Mar 25, 2024
WIP
Contributes to #2247
Contributes to #3117
@eerhardt
Copy link
Member

So we'd represent this in the manifest something like this? "amqp://{urlencode(resources.rabbitusr.value)}:{urlencode(resources.rabbitpw.value)}@{resources.rabbitmq.bindings.tcp.host}:{resources.rabbitmq.bindings.tcp.port}"

Yep - something like that is what I was thinking.

@DamianEdwards
Copy link
Member Author

@davidfowl we thinking punt this until post-GA now? Or do we think this will be common enough when considering values in URIs and connection strings that we need to mitigate it earlier?

@davidfowl
Copy link
Member

yes I think we can do something specifically for URLs and connection strings in azd without putting functions in the manifest (work needs to happen in azd anyways). I’m thinking for now, they can detect a url and do this magic encoding.

@DamianEdwards
Copy link
Member Author

So you're thinking we have AZD recognize URIs and encode themselves for GA?

@eerhardt
Copy link
Member

we have AZD recognize URIs and encode themselves for GA?

And connection strings. (at least that's what I understand from the above)

@davidfowl
Copy link
Member

So you're thinking we have AZD recognize URIs and encode themselves for GA?

Yes, that's how we address this for GA.

And connection strings. (at least that's what I understand from the above)

Yes

@DamianEdwards
Copy link
Member Author

OK I've put in preview.6 and opened Azure/azure-dev#3598

@joperezr joperezr modified the milestones: preview 6 (Apr), 8.1 Apr 8, 2024
@oskardudycz
Copy link

@DamianEdwards I think that Postgres containers have a similar issue.

@mitchdenny
Copy link
Member

Now that we are past GA ... how do we want to handle this?

@joperezr
Copy link
Member

@DamianEdwards is this something we want to fix for 8.1?

@DamianEdwards
Copy link
Member Author

@joperezr if we have a ready-to-go plan to fix it at both runtime and deployment time (i.e. in AZD and Aspir8) otherwise I'd move it out.

@mitchdenny mitchdenny modified the milestones: 8.1, Backlog Jun 24, 2024
@davidfowl davidfowl removed the bug label Oct 16, 2024
@John-Leitch
Copy link

John-Leitch commented Feb 25, 2025

@joperezr, I'm willing to make these changes to Aspir8. I recently made significant changes to adjacent functionality (reference parsing/evaluation), and expect this to be easy. I'd also be more than happy to add function evaluation if that's the direction things go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

No branches or pull requests

8 participants