Skip to content

Commit c3014e0

Browse files
Address review feedback: fix logging, cleanup dead config, improve docs
- Downgrade EC ID/IP log statements from debug to trace to prevent sensitive data appearing in production logs (edge_cookie.rs) - Fix .change_context indentation in HMAC error handling - Remove unused counter_store and opid_store fields from EdgeCookie config struct, all test fixtures, TOML configs, and documentation - Add serialization test asserting ec_fresh wire field name - Fix edge-cookies.md config section reference and consent language - Update error-reference.md to reflect HMAC-based generation - Update configuration.md to remove dead KV store field docs
1 parent 5f77c09 commit c3014e0

File tree

11 files changed

+39
-166
lines changed

11 files changed

+39
-166
lines changed

Cargo.lock

Lines changed: 0 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/trusted-server-core/src/edge_cookie.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn generate_ec_id(
7676
.map(normalize_ip)
7777
.unwrap_or_else(|| "unknown".to_string());
7878

79-
log::debug!("Input for fresh EC ID: client_ip={}", client_ip);
79+
log::trace!("Input for fresh EC ID: client_ip={}", client_ip);
8080

8181
let mut mac = HmacSha256::new_from_slice(settings.edge_cookie.secret_key.expose().as_bytes())
8282
.change_context(TrustedServerError::Ec {
@@ -89,7 +89,7 @@ pub fn generate_ec_id(
8989
let random_suffix = generate_random_suffix(6);
9090
let ec_id = format!("{hmac_hash}.{random_suffix}");
9191

92-
log::debug!("Generated fresh EC ID: {}", ec_id);
92+
log::trace!("Generated fresh EC ID: {}", ec_id);
9393

9494
Ok(ec_id)
9595
}
@@ -108,15 +108,15 @@ pub fn generate_ec_id(
108108
pub fn get_ec_id(req: &Request) -> Result<Option<String>, Report<TrustedServerError>> {
109109
if let Some(ec_id) = req.get_header(HEADER_X_TS_EC).and_then(|h| h.to_str().ok()) {
110110
let id = ec_id.to_string();
111-
log::debug!("Using existing EC ID from header: {}", id);
111+
log::trace!("Using existing EC ID from header: {}", id);
112112
return Ok(Some(id));
113113
}
114114

115115
match handle_request_cookies(req)? {
116116
Some(jar) => {
117117
if let Some(cookie) = jar.get(COOKIE_TS_EC) {
118118
let id = cookie.value().to_string();
119-
log::debug!("Using existing EC ID from cookie: {}", id);
119+
log::trace!("Using existing EC ID from cookie: {}", id);
120120
return Ok(Some(id));
121121
}
122122
}
@@ -149,7 +149,7 @@ pub fn get_or_generate_ec_id(
149149

150150
// If no existing EC ID found, generate a fresh one
151151
let ec_id = generate_ec_id(settings, req)?;
152-
log::debug!("No existing EC ID, generated: {}", ec_id);
152+
log::trace!("No existing EC ID, generated: {}", ec_id);
153153
Ok(ec_id)
154154
}
155155

crates/trusted-server-core/src/integrations/google_tag_manager.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,6 @@ origin_url = "https://origin.test-publisher.com"
13091309
proxy_secret = "test-secret"
13101310
13111311
[edge_cookie]
1312-
counter_store = "test-counter-store"
1313-
opid_store = "test-opid-store"
13141312
secret_key = "test-secret-key"
13151313
13161314
[integrations.google_tag_manager]
@@ -1344,8 +1342,6 @@ origin_url = "https://origin.test-publisher.com"
13441342
proxy_secret = "test-secret"
13451343
13461344
[edge_cookie]
1347-
counter_store = "test-counter-store"
1348-
opid_store = "test-opid-store"
13491345
secret_key = "test-secret-key"
13501346
13511347
[integrations.google_tag_manager]

crates/trusted-server-core/src/integrations/prebid.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,6 @@ origin_url = "https://origin.test-publisher.com"
13091309
proxy_secret = "test-secret"
13101310
13111311
[edge_cookie]
1312-
counter_store = "test-counter-store"
1313-
opid_store = "test-opid-store"
13141312
secret_key = "test-secret-key"
13151313
"#;
13161314

crates/trusted-server-core/src/openrtb.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,24 @@ mod tests {
397397
"ext should be omitted when None"
398398
);
399399
}
400+
401+
#[test]
402+
fn user_ext_serializes_ec_fresh_not_synthetic_fresh() {
403+
let ext = UserExt {
404+
consent: None,
405+
consented_providers_settings: None,
406+
eids: None,
407+
ec_fresh: Some("true".to_string()),
408+
};
409+
410+
let serialized = serde_json::to_value(&ext).expect("should serialize UserExt");
411+
assert_eq!(
412+
serialized["ec_fresh"], "true",
413+
"ec_fresh should be present in serialized output"
414+
);
415+
assert!(
416+
serialized.get("synthetic_fresh").is_none(),
417+
"synthetic_fresh should not appear — field was renamed to ec_fresh"
418+
);
419+
}
400420
}

crates/trusted-server-core/src/settings.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ impl DerefMut for IntegrationSettings {
196196
#[allow(unused)]
197197
#[derive(Debug, Default, Clone, Deserialize, Serialize, Validate)]
198198
pub struct EdgeCookie {
199-
pub counter_store: String,
200-
pub opid_store: String,
201199
#[validate(custom(function = EdgeCookie::validate_secret_key))]
202200
pub secret_key: Redacted<String>,
203201
}
@@ -719,8 +717,6 @@ mod tests {
719717
settings.publisher.origin_url,
720718
"https://origin.test-publisher.com"
721719
);
722-
assert_eq!(settings.edge_cookie.counter_store, "test-counter-store");
723-
assert_eq!(settings.edge_cookie.opid_store, "test-opid-store");
724720
assert_eq!(settings.edge_cookie.secret_key.expose(), "test-secret-key");
725721

726722
settings.validate().expect("Failed to validate settings");
@@ -1424,8 +1420,6 @@ mod tests {
14241420
proxy_secret = "unit-test-proxy-secret"
14251421
14261422
[edge_cookie]
1427-
counter_store = "test-counter-store"
1428-
opid_store = "test-opid-store"
14291423
secret_key = "test-secret-key"
14301424
14311425
[request_signing]

crates/trusted-server-core/src/test_support.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ pub mod tests {
3131
rewrite_attributes = ["href", "link", "url"]
3232
3333
[edge_cookie]
34-
counter_store = "test-counter-store"
35-
opid_store = "test-opid-store"
3634
secret_key = "test-secret-key"
3735
[request_signing]
3836
config_store_id = "test-config-store-id"

docs/guide/configuration.md

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ origin_url = "https://origin.publisher.com"
2424
proxy_secret = "your-secure-secret-here"
2525

2626
[edge_cookie]
27-
counter_store = "counter_store"
28-
opid_store = "opid_store"
2927
secret_key = "your-hmac-secret"
3028
```
3129

@@ -77,8 +75,6 @@ origin_url = "https://origin.publisher.com"
7775
proxy_secret = "change-me-to-secure-value"
7876

7977
[edge_cookie]
80-
counter_store = "counter_store"
81-
opid_store = "opid_store"
8278
secret_key = "your-hmac-secret-key"
8379

8480
[request_signing]
@@ -271,83 +267,25 @@ Settings for generating privacy-preserving Edge Cookie identifiers.
271267

272268
### `[edge_cookie]`
273269

274-
| Field | Type | Required | Description |
275-
| --------------- | ------ | -------- | ---------------------------------------------- |
276-
| `counter_store` | String | Yes | Fastly KV store name for counters |
277-
| `opid_store` | String | Yes | Fastly KV store name for publisher ID mappings |
278-
| `secret_key` | String | Yes | HMAC secret for ID generation |
270+
| Field | Type | Required | Description |
271+
| ------------ | ------ | -------- | ----------------------------- |
272+
| `secret_key` | String | Yes | HMAC secret for ID generation |
279273

280274
**Example**:
281275

282276
```toml
283277
[edge_cookie]
284-
counter_store = "counter_store"
285-
opid_store = "opid_store"
286278
secret_key = "your-secure-hmac-secret"
287279
```
288280

289281
**Environment Override**:
290282

291283
```bash
292-
TRUSTED_SERVER__EDGE_COOKIE__COUNTER_STORE=counter_store
293-
TRUSTED_SERVER__EDGE_COOKIE__OPID_STORE=opid_store
294284
TRUSTED_SERVER__EDGE_COOKIE__SECRET_KEY=your-secret
295285
```
296286

297287
### Field Details
298288

299-
#### `counter_store`
300-
301-
**Purpose**: Fastly KV store for EC ID counters.
302-
303-
**Usage**:
304-
305-
- Stores incrementing counters per domain
306-
- Ensures ID uniqueness
307-
- Accessed via Fastly KV Store API
308-
309-
**Setup**:
310-
311-
```bash
312-
# Create KV store
313-
fastly kv-store create --name=counter_store
314-
```
315-
316-
**Data Format**:
317-
318-
```json
319-
{
320-
"publisher.com": 12345,
321-
"another.com": 67890
322-
}
323-
```
324-
325-
#### `opid_store`
326-
327-
**Purpose**: Fastly KV store for publisher-provided ID mappings.
328-
329-
**Usage**:
330-
331-
- Maps publisher IDs to EC IDs
332-
- Enables first-party ID integration
333-
- Optional (used if publisher provides IDs)
334-
335-
**Setup**:
336-
337-
```bash
338-
# Create KV store
339-
fastly kv-store create --name=opid_store
340-
```
341-
342-
**Data Format**:
343-
344-
```json
345-
{
346-
"publisher-id-123": "ec-abc",
347-
"publisher-id-456": "ec-def"
348-
}
349-
```
350-
351289
#### `secret_key`
352290

353291
**Purpose**: HMAC secret for EC ID base generation.

docs/guide/edge-cookies.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ EC IDs use HMAC (Hash-based Message Authentication Code) to generate a determini
2020

2121
## Configuration
2222

23-
Configure EC secrets in `trusted-server.toml`. See the full [Configuration Reference](/guide/configuration) for the `ec` section and environment variable overrides.
23+
Configure EC secrets in `trusted-server.toml`. See the full [Configuration Reference](/guide/configuration) for the `[edge_cookie]` section and environment variable overrides.
2424

2525
## Privacy Considerations
2626

27-
- IDs are only generated with explicit user consent
28-
- No personally identifiable information (PII) is included
27+
- EC IDs are generated deterministically from the client IP, but the cookie is only set when storage consent is present
28+
- No personally identifiable information (PII) is stored in the ID
2929
- The hash input is the client IP address only
30-
- IDs can be rotated on schedule
30+
- IDs can be rotated by changing the secret key
3131

3232
## Best Practices
3333

docs/guide/error-reference.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,30 +134,24 @@ See [Configuration Reference](./configuration.md) for complete patterns.
134134
**Error Message:**
135135

136136
```
137-
Failed to generate EC ID: KV store not available
137+
Failed to generate EC ID: HMAC error
138138
```
139139

140-
**Cause:** KV store (counter_store or opid_store) not configured in Fastly
140+
**Cause:** HMAC secret key is missing or invalid in the Edge Cookie configuration.
141141

142142
**Solution:**
143143

144-
1. Create KV stores in Fastly dashboard
145-
2. Link them to your Compute service
146-
3. Update `trusted-server.toml`:
144+
1. Ensure `secret_key` is set in `trusted-server.toml`:
147145

148146
```toml
149147
[edge_cookie]
150-
counter_store = "counter_store" # Must match Fastly KV store name
151-
opid_store = "opid_store"
148+
secret_key = "your-secure-hmac-secret"
152149
```
153150

154-
4. For local development, configure in `fastly.toml`:
151+
2. Or set via environment variable:
155152

156-
```toml
157-
[local_server.kv_stores]
158-
[[local_server.kv_stores.counter_store]]
159-
key = "placeholder"
160-
data = "placeholder"
153+
```bash
154+
TRUSTED_SERVER__EDGE_COOKIE__SECRET_KEY=your-secure-hmac-secret
161155
```
162156

163157
---

0 commit comments

Comments
 (0)