Security

The API payload security pipeline: order, protection levels and keys

DEV Community: #dotnet Jeff Tsai
Security

An ERP framework's API payload pipeline runs serialization, compression and encryption in a fixed order, then compares the format a call actually used against the protection level its method declares. The post explains why that order cannot be swapped and what sits behind the aes-cbc-hmac name, down to key sourcing.

Key points

  • Compression must precede encryption; the reverse order makes gzip useless and grows the payload beyond three times its size.
  • On the way back each stage only sees bytes that passed the previous one, so the HMAC is verified before anything is decrypted.
  • PayloadFormat records what a call actually did; ApiProtectionLevel (Public, Encoded, Encrypted, LocalOnly) declares the minimum it accepts.
  • A format below the declared level is refused, while LocalOnly is judged separately: it simply rejects calls that arrive over the network.
  • The 64-byte key is split in two: the first 32 bytes encrypt with AES, the last 32 authenticate with HMAC.
  • HMAC checks use `CryptographicOperations.FixedTimeEquals`, and a wrong key, bad ciphertext and bad tag all return the same error.

Real-world use

  • An ERP API where a front end without a .NET runtime must reach its first method without implementing the whole encryption pipeline
  • Endpoints that manage API keys and must not leave their content as plain text inside the server
  • Definition-writing methods that only the host process itself should start, never a remote caller
  • Sessions rebuilt from a database seed where encrypted calls must keep working after the rebuild

This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message