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

Aspire: Encode values inserted into URIs and connection strings #3598

Open
DamianEdwards opened this issue Mar 26, 2024 · 2 comments
Open

Aspire: Encode values inserted into URIs and connection strings #3598

DamianEdwards opened this issue Mar 26, 2024 · 2 comments
Assignees
Milestone

Comments

@DamianEdwards
Copy link
Contributor

See dotnet/aspire#3117

When a value in an Aspire manifest is detected as a URI or connection string format, expressions within that value should be appropriately escaped, e.g. the expressions in the following value should be URL escaped: "amqp://{resources.rabbitusr.value}:{resources.rabbitpw.value}@{resources.rabbitmq.bindings.tcp.host}:{resources.rabbitmq.bindings.tcp.port}"

@danm-de
Copy link

danm-de commented Oct 2, 2024

Would it be possible to implement a projection function for ReferenceExpression in which we can modify the values? Are there any serialization scenarios in which the Func<T,TResult> would be a problem?

Example:

/// <summary>
/// Gets the connection string expression with credentials for the RabbitMQ server.
/// </summary>
public ReferenceExpression ConnectionStringExpression
{
    get
    {
        var encodedUserReference = UserReference.Select(value => HttpUtility.UrlEncode(value));
        var encodedPasswordReference = PasswordReference.Select(value => HttpUtility.UrlEncode(value));
        
        return ReferenceExpression.Create(
            $"amqp://{encodedUserReference}:{encodedPasswordReference}@{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
    }
}

@DamianEdwards
Copy link
Contributor Author

I think the issue is the expression has to be evaluated by the reader, e.g. azd, so the encoding itself can't be implemented in the app host. Rather it needs a value written out to the manifest like amqp://{urlencode(resources.rabbitusr.value)}:{urlencode(resources.rabbitpw.value)}@{resources.rabbitmq.bindings.tcp.host}:{resources.rabbitmq.bindings.tcp.port}

@rajeshkamal5050 rajeshkamal5050 modified the milestones: Dilithium, On Deck Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants