Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions 13/umbraco-cms/reference/configuration/imagingsettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"Resize": {
"MaxWidth": 5000,
"MaxHeight": 5000
}
},
"HMACSecretKey": ""
}
}
}
```

## Cache

Contains configuration for browser and server caching.
Contains configuration for browser and server caching.
When changing these cache headers, it is recommended to clear your media cache. This is due to the data being stored in the cache and not updated when the configuration is changed.

### Browser max age
Expand Down Expand Up @@ -82,3 +83,70 @@
});
}
```

## HMAC secret key

Check failure on line 87 in 13/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "13/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 87, "column": 4}}}, "severity": "ERROR"}

Specifies the key used to secure image requests by generating a hash-based message authentication code (HMAC). This ensures that only valid requests can access or manipulate images.

Check failure on line 89 in 13/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "13/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 89, "column": 105}}}, "severity": "ERROR"}

To enable it, you need to set a secure random key. This key should be kept secret and not shared publicly. The key can be set through the `IOptions` pattern, or you can insert a base64 encoded key in the `appsettings.json` file. The key should ideally be 64 bytes long.

The key must be the same across all environments (development, staging, production) to ensure that image requests work for content published across environments.

### Default Behavior

If the `HMACSecretKey` is not set, image requests are not secured, and any person can request images with any parameters. This may expose your server to abuse, such as excessive resizing requests or unauthorized access to images.

### Key Length

The `HMACSecretKey` should be a secure, random key. For most use cases, a 64-byte (512-bit) key is recommended. If you are using `HMACSHA384` or `HMACSHA512`, you may want to use a longer key (for example: 128 bytes).

### Example Configuration

**appsettings.json**
```json
"Umbraco": {
"CMS": {
"Imaging": {
"HMACSecretKey": "some-base64-encoded-key"
}
}
}
```

**Using the `IOptions` pattern**

To generate the `HMACSecretKey` programmatically instead of hardcoding it in configuration files, use the `IOptions` pattern. The following example demonstrates how to generate a secure random key at runtime:

```csharp
using System.Security.Cryptography;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;

public class HMACSecretKeyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
=> builder.Services.Configure<ImagingSettings>(options =>
{
if (options.HMACSecretKey.Length == 0)
{
byte[] secret = new byte[64]; // Change to 128 when using HMACSHA384 or HMACSHA512
RandomNumberGenerator.Create().GetBytes(secret);
options.HMACSecretKey = secret;

var logger = builder.BuilderLoggerFactory.CreateLogger<HMACSecretKeyComposer>();
logger.LogInformation("Imaging settings is now using HMACSecretKey: {HMACSecretKey}", Convert.ToBase64String(secret));
}
});
}
```

{% hint style="warning" %}
The `HMACSecretKey` must be kept secret and never exposed publicly. If the key is exposed, malicious users may generate valid HMACs and exploit server resources.
{% endhint %}

### Testing the Configuration

To verify that your `HMACSecretKey` is working correctly:
1. Set the `HMACSecretKey` key in the `appsettings.json` file or via the `IOptions` pattern.
2. Make a request to an image URL with valid parameters and ensure it works as expected.
3. Modify the URL parameters or remove the HMAC signature and confirm that the request is rejected.

Check failure on line 152 in 13/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "13/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 152, "column": 44}}}, "severity": "ERROR"}
72 changes: 70 additions & 2 deletions 14/umbraco-cms/reference/configuration/imagingsettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"Resize": {
"MaxWidth": 5000,
"MaxHeight": 5000
}
},
"HMACSecretKey": ""
}
}
}
```

## Cache

Contains configuration for browser and server caching.
Contains configuration for browser and server caching.
When changing these cache headers, it is recommended to clear your media cache. This is due to the data being stored in the cache and not updated when the configuration is changed.

### Browser max age
Expand Down Expand Up @@ -82,3 +83,70 @@
});
}
```

## HMAC secret key

Check failure on line 87 in 14/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "14/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 87, "column": 4}}}, "severity": "ERROR"}

Specifies the key used to secure image requests by generating a hash-based message authentication code (HMAC). This ensures that only valid requests can access or manipulate images.

Check failure on line 89 in 14/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "14/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 89, "column": 105}}}, "severity": "ERROR"}

To enable it, you need to set a secure random key. This key should be kept secret and not shared publicly. The key can be set through the `IOptions` pattern, or you can insert a base64 encoded key in the `appsettings.json` file. The key should ideally be 64 bytes long.

The key must be the same across all environments (development, staging, production) to ensure that image requests work for content published across environments.

### Default Behavior

If the `HMACSecretKey` is not set, image requests are not secured, and any person can request images with any parameters. This may expose your server to abuse, such as excessive resizing requests or unauthorized access to images.

### Key Length

The `HMACSecretKey` should be a secure, random key. For most use cases, a 64-byte (512-bit) key is recommended. If you are using `HMACSHA384` or `HMACSHA512`, you may want to use a longer key (for example: 128 bytes).

### Example Configuration

**appsettings.json**
```json
"Umbraco": {
"CMS": {
"Imaging": {
"HMACSecretKey": "some-base64-encoded-key"
}
}
}
```

**Using the `IOptions` pattern**

To generate the `HMACSecretKey` programmatically instead of hardcoding it in configuration files, use the `IOptions` pattern. The following example demonstrates how to generate a secure random key at runtime:

```csharp
using System.Security.Cryptography;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;

public class HMACSecretKeyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
=> builder.Services.Configure<ImagingSettings>(options =>
{
if (options.HMACSecretKey.Length == 0)
{
byte[] secret = new byte[64]; // Change to 128 when using HMACSHA384 or HMACSHA512
RandomNumberGenerator.Create().GetBytes(secret);
options.HMACSecretKey = secret;

var logger = builder.BuilderLoggerFactory.CreateLogger<HMACSecretKeyComposer>();
logger.LogInformation("Imaging settings is now using HMACSecretKey: {HMACSecretKey}", Convert.ToBase64String(secret));
}
});
}
```

{% hint style="warning" %}
The `HMACSecretKey` must be kept secret and never exposed publicly. If the key is exposed, malicious users may generate valid HMACs and exploit server resources.
{% endhint %}

### Testing the Configuration

To verify that your `HMACSecretKey` is working correctly:
1. Set the `HMACSecretKey` key in the `appsettings.json` file or via the `IOptions` pattern.
2. Make a request to an image URL with valid parameters and ensure it works as expected.
3. Modify the URL parameters or remove the HMAC signature and confirm that the request is rejected.

Check failure on line 152 in 14/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "14/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 152, "column": 44}}}, "severity": "ERROR"}
72 changes: 70 additions & 2 deletions 15/umbraco-cms/reference/configuration/imagingsettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"Resize": {
"MaxWidth": 5000,
"MaxHeight": 5000
}
},
"HMACSecretKey": ""
}
}
}
```

## Cache

Contains configuration for browser and server caching.
Contains configuration for browser and server caching.
When changing these cache headers, it is recommended to clear your media cache. This is due to the data being stored in the cache and not updated when the configuration is changed.

### Browser max age
Expand Down Expand Up @@ -82,3 +83,70 @@
});
}
```

## HMAC secret key

Check failure on line 87 in 15/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "15/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 87, "column": 4}}}, "severity": "ERROR"}

Specifies the key used to secure image requests by generating a hash-based message authentication code (HMAC). This ensures that only valid requests can access or manipulate images.

Check failure on line 89 in 15/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "15/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 89, "column": 105}}}, "severity": "ERROR"}

To enable it, you need to set a secure random key. This key should be kept secret and not shared publicly. The key can be set through the `IOptions` pattern, or you can insert a base64 encoded key in the `appsettings.json` file. The key should ideally be 64 bytes long.

The key must be the same across all environments (development, staging, production) to ensure that image requests work for content published across environments.

### Default Behavior

If the `HMACSecretKey` is not set, image requests are not secured, and any person can request images with any parameters. This may expose your server to abuse, such as excessive resizing requests or unauthorized access to images.

### Key Length

The `HMACSecretKey` should be a secure, random key. For most use cases, a 64-byte (512-bit) key is recommended. If you are using `HMACSHA384` or `HMACSHA512`, you may want to use a longer key (for example: 128 bytes).

### Example Configuration

**appsettings.json**
```json
"Umbraco": {
"CMS": {
"Imaging": {
"HMACSecretKey": "some-base64-encoded-key"
}
}
}
```

**Using the `IOptions` pattern**

To generate the `HMACSecretKey` programmatically instead of hardcoding it in configuration files, use the `IOptions` pattern. The following example demonstrates how to generate a secure random key at runtime:

```csharp
using System.Security.Cryptography;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;

public class HMACSecretKeyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
=> builder.Services.Configure<ImagingSettings>(options =>
{
if (options.HMACSecretKey.Length == 0)
{
byte[] secret = new byte[64]; // Change to 128 when using HMACSHA384 or HMACSHA512
RandomNumberGenerator.Create().GetBytes(secret);
options.HMACSecretKey = secret;

var logger = builder.BuilderLoggerFactory.CreateLogger<HMACSecretKeyComposer>();
logger.LogInformation("Imaging settings is now using HMACSecretKey: {HMACSecretKey}", Convert.ToBase64String(secret));
}
});
}
```

{% hint style="warning" %}
The `HMACSecretKey` must be kept secret and never exposed publicly. If the key is exposed, malicious users may generate valid HMACs and exploit server resources.
{% endhint %}

### Testing the Configuration

To verify that your `HMACSecretKey` is working correctly:
1. Set the `HMACSecretKey` key in the `appsettings.json` file or via the `IOptions` pattern.
2. Make a request to an image URL with valid parameters and ensure it works as expected.
3. Modify the URL parameters or remove the HMAC signature and confirm that the request is rejected.

Check failure on line 152 in 15/umbraco-cms/reference/configuration/imagingsettings.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.Acronyms] 'HMAC' has no definition Raw Output: {"message": "[UmbracoDocs.Acronyms] 'HMAC' has no definition", "location": {"path": "15/umbraco-cms/reference/configuration/imagingsettings.md", "range": {"start": {"line": 152, "column": 44}}}, "severity": "ERROR"}
72 changes: 70 additions & 2 deletions 16/umbraco-cms/reference/configuration/imagingsettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ All these settings contain default values, so nothing needs to be explicitly con
"Resize": {
"MaxWidth": 5000,
"MaxHeight": 5000
}
},
"HMACSecretKey": ""
}
}
}
```

## Cache

Contains configuration for browser and server caching.
Contains configuration for browser and server caching.
When changing these cache headers, it is recommended to clear your media cache. This is due to the data being stored in the cache and not updated when the configuration is changed.

### Browser max age
Expand Down Expand Up @@ -82,3 +83,70 @@ public class ConfigureImageSharpMiddlewareOptionsComposer : IComposer
});
}
```

## HMAC secret key

Specifies the key used to secure image requests by generating a hash-based message authentication code (HMAC). This ensures that only valid requests can access or manipulate images.

To enable it, you need to set a secure random key. This key should be kept secret and not shared publicly. The key can be set through the `IOptions` pattern, or you can insert a base64 encoded key in the `appsettings.json` file. The key should ideally be 64 bytes long.

The key must be the same across all environments (development, staging, production) to ensure that image requests work for content published across environments.

### Default Behavior

If the `HMACSecretKey` is not set, image requests are not secured, and any person can request images with any parameters. This may expose your server to abuse, such as excessive resizing requests or unauthorized access to images.

### Key Length

The `HMACSecretKey` should be a secure, random key. For most use cases, a 64-byte (512-bit) key is recommended. If you are using `HMACSHA384` or `HMACSHA512`, you may want to use a longer key (for example: 128 bytes).

### Example Configuration

**appsettings.json**
```json
"Umbraco": {
"CMS": {
"Imaging": {
"HMACSecretKey": "some-base64-encoded-key"
}
}
}
```

**Using the `IOptions` pattern**

To generate the `HMACSecretKey` programmatically instead of hardcoding it in configuration files, use the `IOptions` pattern. The following example demonstrates how to generate a secure random key at runtime:

```csharp
using System.Security.Cryptography;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;

public class HMACSecretKeyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
=> builder.Services.Configure<ImagingSettings>(options =>
{
if (options.HMACSecretKey.Length == 0)
{
byte[] secret = new byte[64]; // Change to 128 when using HMACSHA384 or HMACSHA512
RandomNumberGenerator.Create().GetBytes(secret);
options.HMACSecretKey = secret;

var logger = builder.BuilderLoggerFactory.CreateLogger<HMACSecretKeyComposer>();
logger.LogInformation("Imaging settings is now using HMACSecretKey: {HMACSecretKey}", Convert.ToBase64String(secret));
}
});
}
```

{% hint style="warning" %}
The `HMACSecretKey` must be kept secret and never exposed publicly. If the key is exposed, malicious users may generate valid HMACs and exploit server resources.
{% endhint %}

### Testing the Configuration

To verify that your `HMACSecretKey` is working correctly:
1. Set the `HMACSecretKey` key in the `appsettings.json` file or via the `IOptions` pattern.
2. Make a request to an image URL with valid parameters and ensure it works as expected.
3. Modify the URL parameters or remove the HMAC signature and confirm that the request is rejected.
Loading