NAME

Azure::SDK::Storage::Blobs::Serializer - parse Azure Blob XML payloads

SYNOPSIS

use Azure::SDK::Storage::Blobs::Serializer;

my $serializer = Azure::SDK::Storage::Blobs::Serializer->new;

my $page  = $serializer->parse_blob_list($list_xml);
my $error = $serializer->parse_error($error_xml);

DESCRIPTION

Parses the two XML payloads the Blob service returns: the EnumerationResults document of a container listing, and the Error envelope of a failed request.

Parsing is namespace-agnostic (local-name() XPath), so the client keeps working if the service starts emitting a default namespace.

Parser hardening

Response bodies are untrusted input, so the parser is configured to resolve nothing outside the body itself:

  • no_network and load_ext_dtd are disabled, and an ext_ent_handler that throws is installed, so no external entity or DTD can be fetched (CWE-611).

  • expand_entities is disabled and huge is off, so entity-expansion blowups are not possible (CWE-776).

  • A parsed document that carries any document type declaration is rejected outright. A Blob response never has one, so this removes the attack class rather than relying on parser flags alone.

  • Bodies larger than max_bytes (8 MiB by default) are rejected before parsing, so a hostile or corrupted response cannot drive unbounded memory use (CWE-770). The limit is measured in bytes rather than Perl characters, so an already-decoded body cannot exceed it while appearing to fit.

  • Blob names flagged Encoded="true" are decoded through "decode_component" in Azure::SDK::Storage::Blobs::Uri, which rejects incomplete percent-escapes and invalid UTF-8. A name is read from one response and fed straight into the next request, so a malformed name accepted here would be re-encoded into a well-formed request for a different blob.

CONSTRUCTOR

new

Named parameter max_bytes, a positive integer that defaults to 8 MiB.

METHODS

parse_blob_list

my $page = $serializer->parse_blob_list($xml);

Returns an Azure::SDK::Storage::Blobs::BlobPage. Blob names flagged with Encoded="true" are percent-decoded and treated as UTF-8. Croaks when the document is not an EnumerationResults payload.

parse_error

my $error = $serializer->parse_error($xml);

Returns a hash reference with code and message, or undef when the body is absent or is not an Error envelope. Returning undef rather than croaking is deliberate: Azurite answers some failures (for example a listing that contains a blob name it cannot serialize) with HTTP 500 and an empty body, and the caller must still be able to raise a useful error from the status code and the x-ms-error-code header.

The returned message is raw server text. It contains newlines in practice, so route it through Azure::SDK::Core::Error before logging it.

SEE ALSO

Azure::SDK::Storage::Blobs::BlobPage, Azure::SDK::Storage::Blobs::BlobItem, Azure::SDK::Core::Error