Lesson 6 of 6 Edge Protection and Application Security

Restricting Content Delivery at the Edge

This lesson explains how CloudFront enforces restrictions at the edge for content that only some users may see, such as paid videos, customer documents, members' areas or content licensed for particular countries.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose between signed URLs and signed cookies.
  • Describe geographic restrictions and their limits.
  • Explain how field-level encryption protects sensitive fields.

Signed URLs and signed cookies

To restrict content to paying or authenticated users, the application signs access with a private key whose public key is in a trusted key group on the distribution's cache behavior. (Older CloudFront key pairs required the root user and are not recommended.)

There are three ways to grant temporary access. A signed URL grants access to one file and suits individual downloads, or clients that do not support cookies. Signed cookies grant access to many files without changing their URLs, such as every segment of an HLS video stream or a whole members' area. An S3 presigned URL is different: it grants direct, short-lived access to a single S3 object without CloudFront. The following table summarises the options.

UseWhen
Signed URLAccess to individual files, or clients that do not support cookies
Signed cookiesAccess to many files, such as all segments of an HLS video or a members area, without changing URLs
S3 presigned URLDirect, short-lived access to a single S3 object without CloudFront

Canned policies restrict by expiry time only; custom policies can also restrict by start time and source IP range, and can cover many files with a wildcard.

Geographic restrictions

CloudFront geographic restrictions allow or block whole countries for a distribution, which suits content licensed only for particular markets. Finer rules, such as blocking a country only on certain paths, or combining location with other conditions such as headers, use AWS WAF geo match statements in the distribution's web ACL.

In both cases the country is determined from the viewer's IP address, so these controls enforce licensing and policy for ordinary users but are not a defence against determined users who route through proxies or VPNs in permitted countries.

Protecting sensitive fields

HTTPS protects data in transit to CloudFront and to the origin, but once a request reaches the application, every tier that handles it, including logging, caching and intermediate services, can see its contents. Field-level encryption encrypts chosen fields of a POST request, such as a card number, at the edge with a public key. Only the component that holds the matching private key, typically one payment service, can decrypt them, so other tiers, logs and caches see only ciphertext, which reduces the part of the system that is in scope for standards such as PCI DSS.

Worked example

A media company serves premium videos as HLS streams from S3 through CloudFront. Only subscribers may watch, and each video consists of hundreds of segment files. Videos must not be downloadable directly from S3.

OAC with a bucket policy limited to the distribution stops direct S3 access. Because each video has hundreds of files, signed cookies issued after the subscriber logs in are better than signing every segment URL. The cache behavior for premium content uses a trusted key group.

Check yourself

When are signed cookies better than signed URLs?

Show answer

When a user must access many files, such as all segments of a video or a members' area, without each URL being changed.

Exam Tips

Remember for the exam

  • Signed cookies for many files, signed URLs for individual files; use trusted key groups.
  • Custom policies restrict by start time, expiry and source IP range.
  • For country-level restrictions, use CloudFront geographic restrictions; for finer rules, WAF geo match.
  • Field-level encryption protects specific POST fields from the edge to the back end.
  • S3 presigned URLs give short-lived access to single objects without CloudFront.