Skip to content

Commit 7279e14

Browse files
Web3NLclaude
andcommitted
docs: update changelogs and README for frontend crate improvements
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8f941f3 commit 7279e14

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

packages-rs/canister-dapp-test/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Added
66

7+
- Security header validation: all 8 security/privacy headers verified on frontend fallback responses
8+
- Gzip compression test: verifies Accept-Encoding negotiation returns compressed responses with correct headers
79
- CLI binary: `canister-dapp-test <wasm-path>` runs the full acceptance suite against any dapp WASM.
810
- HTTP response header validation: Content-Type for HTML/JS/CSS, Content-Security-Policy for dashboard HTML.
911
- SPA fallback test: unknown paths serve index.html with 200 (client-side routing).

packages-rs/my-canister-frontend/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- 8 default security/privacy HTTP headers on all asset responses: X-Content-Type-Options, X-Frame-Options, Referrer-Policy, X-XSS-Protection, Strict-Transport-Security, Permissions-Policy, Cross-Origin-Opener-Policy, Cross-Origin-Resource-Policy
8+
- Asset validation: file type allowlist, 2 MB size limit, duplicate path detection, path traversal and malformed URL rejection
9+
- Gzip compression for text-based assets (HTML, JS, CSS, JSON, SVG, XML, TXT, source maps)
10+
- `FrontendConfig` struct for customization (extra allowed extensions, custom size limit)
11+
- `setup_frontend_with_config()` for configurable frontend initialization
12+
- `asset_router_configs_with_config()` for configurable asset processing
13+
14+
### Changed
15+
16+
- `asset_router_configs()` now returns `Result` to surface validation errors (breaking)
17+
- Compressible assets are served with both Identity and Gzip encodings
18+
19+
### Dependencies
20+
21+
- Added `flate2` for gzip compression
22+
523
## [0.2.1] - 2025-09-11
624

725
### Changed

packages-rs/my-canister-frontend/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,34 @@ fn http_request(req: HttpRequest) -> HttpResponse {
3737
- Automatic MIME type detection using `mime_guess`
3838
- `index.html` auto-configured as fallback for `/`
3939
- Certification using [`ic-asset-certification`](https://docs.rs/ic-asset-certification)
40+
- **Security headers**: 8 default security/privacy headers on all responses (HSTS, X-Frame-Options, Referrer-Policy, etc.)
41+
- **Asset validation**: File type allowlist, 2 MB size limit, path traversal protection, duplicate detection
42+
- **Gzip compression**: Automatic gzip for text-based assets (HTML, JS, CSS, JSON, SVG)
43+
- **Configurable**: Use `FrontendConfig` to allow additional file types or adjust size limits
4044
- Exposes `with_asset_router` and `with_asset_router_mut` for access to the asset router, see example below.
4145
- Exposes `asset_router_configs` if you want to implement your own asset router, see [this example](https://github.com/Web3NL/my-canister-dapp/blob/e8fdc0ac81f7bdc702418c05130ace3f9f5399fb/examples/my-hello-world/src/backend/src/lib.rs).
4246

47+
## Configuration
48+
49+
To allow additional file types or customize settings:
50+
51+
```rust,ignore
52+
use ic_cdk::init;
53+
use include_dir::{include_dir, Dir};
54+
use my_canister_frontend::{setup_frontend_with_config, FrontendConfig};
55+
56+
static ASSETS: Dir = include_dir!("$CARGO_MANIFEST_DIR/../dapp-frontend/dist");
57+
58+
#[init]
59+
fn init() {
60+
let config = FrontendConfig {
61+
extra_allowed_extensions: vec!["webmanifest".to_string()],
62+
..Default::default()
63+
};
64+
setup_frontend_with_config(&ASSETS, &config).expect("Failed to setup frontend");
65+
}
66+
```
67+
4368
## Usage with [`my_canister_dashboard`](https://crates.io/crates/my-canister-dashboard)
4469

4570
```rust,ignore

0 commit comments

Comments
 (0)