Skip to content

Expose WebSocketMessageFlags in ClientWebSocket #77783

Closed

Description

@greenEkatherine

In #31088 compression support in WebSocket was introduced. There was added WebSocketMessageFlags.DisableCompression flag which is needed to turn off compression i.e. when sending data containing secrets -- it helps to avoid CRIME/BREACH attacks.

However, this flag was added only in WebSocket and not in ClientWebSocket which is supposed to manage messages. We need to expose DisableCompression flag in SendAsync methods as well as it is done for EndOfMessage flag.

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 2, 2022
  2. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Nov 2, 2022
  3. stephentoub commented on Nov 2, 2022

    @stephentoub
    Member

    I've not quite followed the proposal. ClientWebSocket derives from WebSocket, inheriting all the APIs added there, and its implementation wraps ManagedWebSocket that implements the compression. What is the specific API that would be added to ClientWebSocket?

  4. greenEkatherine commented on Nov 3, 2022

    @greenEkatherine
    ContributorAuthor

    @stephentoub we should add SendAsync method that handles DisableCompression flag. Currently we handle only EndOfMessage flag in both ClientWebSocket

    public override Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) =>
    ConnectedWebSocket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
    public override ValueTask SendAsync(ReadOnlyMemory<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) =>
    ConnectedWebSocket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
    and parent WebSocket
    public virtual ValueTask SendAsync(ReadOnlyMemory<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) =>
    MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> arraySegment) ?
    new ValueTask(SendAsync(arraySegment, messageType, endOfMessage, cancellationToken)) :
    SendWithArrayPoolAsync(buffer, messageType, endOfMessage, cancellationToken);
    public virtual ValueTask SendAsync(ReadOnlyMemory<byte> buffer, WebSocketMessageType messageType, WebSocketMessageFlags messageFlags, CancellationToken cancellationToken = default)
    {
    return SendAsync(buffer, messageType, messageFlags.HasFlag(WebSocketMessageFlags.EndOfMessage), cancellationToken);
    }

  5. stephentoub commented on Nov 3, 2022

    @stephentoub
    Member

    Thanks. This isn't about missing API, then, it's a bug. ClientWebSocket should be overriding public virtual ValueTask SendAsync(ReadOnlyMemory<byte> buffer, WebSocketMessageType messageType, WebSocketMessageFlags messageFlags, CancellationToken cancellationToken = default) to forward it to the wrapped ManagedWebSocket's corresponding overload.

  6. added and removed
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Nov 3, 2022
  7. MihaZupan commented on Nov 3, 2022

    @MihaZupan
    Member

    Triage: We should fix this in 8.0, looks like we're missing test coverage as well.

  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 3, 2022
  9. added this to the 8.0.0 milestone on Nov 3, 2022
  10. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Dec 8, 2022
  11. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Dec 12, 2022
  12. CarnaViire commented on Dec 12, 2022

    @CarnaViire
    Member

    Reopening for backport

  13. modified the milestones: 8.0.0, 6.0.x on Dec 13, 2022
  14. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Dec 13, 2022
  15. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 5, 2023
  16. karelz commented on Jan 6, 2023

    @karelz
    Member

    Fixed in 8.0 (main) in PR #79412, and in 7.0.3 in PR #79547, and in 6.0.14 in PR #79549.

  17. ghost locked as resolved and limited conversation to collaborators on Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions