Skip to content

Commit 958db42

Browse files
committed
fix(MessagePack): remove MessagePackSecurity.Untrusted as default on AspNetCore
Custom structs, including Nodatime ones, would cause "No hash-resistant equality comparer available for type: NodaTime.LocalDateTime". Disable by default. Wait for Nodatime.MessagePack to support it.
1 parent 1d50ea4 commit 958db42

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

Diff for: Ark.Tools.AspNetCore.MessagePack/LZ4MessagePackInputFormatter.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@ public class LZ4MessagePackInputFormatter : InputFormatter
1818
readonly MessagePackSerializerOptions _options;
1919

2020
public LZ4MessagePackInputFormatter()
21-
: this(null)
21+
: this(MessagePackSerializer.DefaultOptions)
2222
{
2323
}
2424

25-
public LZ4MessagePackInputFormatter(IFormatterResolver? resolver)
25+
public LZ4MessagePackInputFormatter(IFormatterResolver resolver)
26+
: this(MessagePackSerializer.DefaultOptions.WithResolver(resolver))
2627
{
27-
SupportedMediaTypes.Add(ContentType);
28+
}
2829

29-
if (resolver == null)
30-
_options = MessagePackSerializer.DefaultOptions;
31-
else
32-
_options = MessagePackSerializer.DefaultOptions.WithResolver(resolver);
30+
public LZ4MessagePackInputFormatter(MessagePackSerializerOptions options)
31+
{
32+
SupportedMediaTypes.Add(ContentType);
3333

34-
_options = _options.WithCompression(MessagePackCompression.Lz4Block);
35-
_options = _options.WithSecurity(MessagePackSecurity.UntrustedData);
34+
_options = options.WithCompression(MessagePackCompression.Lz4Block);
3635
}
3736

3837
protected override bool CanReadType(Type type)

Diff for: Ark.Tools.AspNetCore.MessagePack/LZ4MessagePackOutputFormatter.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ public class LZ4MessagePackOutputFormatter : OutputFormatter
1616
readonly MessagePackSerializerOptions _options;
1717

1818
public LZ4MessagePackOutputFormatter()
19-
: this(null)
19+
: this(MessagePackSerializer.DefaultOptions)
2020
{
2121
}
2222

23-
public LZ4MessagePackOutputFormatter(IFormatterResolver? resolver)
23+
public LZ4MessagePackOutputFormatter(IFormatterResolver resolver)
24+
: this(MessagePackSerializer.DefaultOptions.WithResolver(resolver))
2425
{
25-
SupportedMediaTypes.Add(_contentType);
26+
}
2627

27-
if (resolver == null)
28-
_options = MessagePackSerializer.DefaultOptions;
29-
else
30-
_options = MessagePackSerializer.DefaultOptions.WithResolver(resolver);
28+
public LZ4MessagePackOutputFormatter(MessagePackSerializerOptions options)
29+
{
30+
SupportedMediaTypes.Add(_contentType);
3131

32-
_options = _options.WithCompression(MessagePackCompression.Lz4Block);
32+
_options = options.WithCompression(MessagePackCompression.Lz4Block);
3333
}
3434

3535
protected override bool CanWriteType(Type? type)

Diff for: Ark.Tools.AspNetCore.MessagePack/MessagePackInputFormatter.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ public class MessagePackInputFormatter : InputFormatter
1818
readonly MessagePackSerializerOptions _options;
1919

2020
public MessagePackInputFormatter()
21-
: this(null)
21+
: this(MessagePackSerializer.DefaultOptions)
2222
{
2323
}
2424

25-
public MessagePackInputFormatter(IFormatterResolver? resolver)
25+
public MessagePackInputFormatter(IFormatterResolver resolver)
26+
: this(MessagePackSerializer.DefaultOptions.WithResolver(resolver))
2627
{
27-
SupportedMediaTypes.Add(ContentType);
28+
}
2829

29-
if (resolver == null)
30-
_options = MessagePackSerializer.DefaultOptions;
31-
else
32-
_options = MessagePackSerializer.DefaultOptions.WithResolver(resolver);
30+
public MessagePackInputFormatter(MessagePackSerializerOptions options)
31+
{
32+
SupportedMediaTypes.Add(ContentType);
3333

34-
_options = _options.WithSecurity(MessagePackSecurity.UntrustedData);
34+
_options = options;
3535
}
3636

3737
protected override bool CanReadType(Type type)

Diff for: Ark.Tools.AspNetCore.MessagePack/MessagePackOutputFormatter.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ public class MessagePackOutputFormatter : OutputFormatter
1616
readonly MessagePackSerializerOptions _options;
1717

1818
public MessagePackOutputFormatter()
19-
: this(null)
19+
: this(MessagePackSerializer.DefaultOptions)
2020
{
2121
}
22-
public MessagePackOutputFormatter(IFormatterResolver? resolver)
22+
23+
public MessagePackOutputFormatter(IFormatterResolver resolver)
24+
: this(MessagePackSerializer.DefaultOptions.WithResolver(resolver))
25+
{
26+
}
27+
28+
public MessagePackOutputFormatter(MessagePackSerializerOptions options)
2329
{
2430
SupportedMediaTypes.Add(_contentType);
2531

26-
if (resolver == null)
27-
_options = MessagePackSerializer.DefaultOptions;
28-
else
29-
_options = MessagePackSerializer.DefaultOptions.WithResolver(resolver);
32+
_options = options;
3033
}
3134

3235
protected override bool CanWriteType(Type? type)

0 commit comments

Comments
 (0)