Skip to content

Comments

docs: cookbook additions (Security Headers, File Upload Safety)#133

Closed
Tuntii wants to merge 1 commit intomainfrom
docs/cookbook-security-updates-13544147916072688995
Closed

docs: cookbook additions (Security Headers, File Upload Safety)#133
Tuntii wants to merge 1 commit intomainfrom
docs/cookbook-security-updates-13544147916072688995

Conversation

@Tuntii
Copy link
Owner

@Tuntii Tuntii commented Feb 23, 2026

This PR improves the RustAPI Cookbook by adding a dedicated recipe for Security Headers and enhancing the File Uploads guide with critical safety information regarding memory usage and manual validation. It also refines the Learning Path to better scaffold validation concepts and introduces a documentation coverage map for internal tracking.


PR created automatically by Jules for task 13544147916072688995 started by @Tuntii

- Added new recipe: `security_headers.md` (HSTS, CSP, X-Frame-Options).
- Updated `file_uploads.md`: Added warnings about memory buffering and examples for manual validation.
- Updated `advanced_middleware.md`: Added reverse proxy configuration section.
- Enhanced Learning Path Module 5 with a specific mini-project.
- Created `docs/.agent/docs_coverage.md` to track documentation gaps.
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings February 23, 2026 03:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the RustAPI Cookbook with critical security and safety documentation. It adds a comprehensive Security Headers recipe covering HSTS, CSP, and X-Frame-Options, and significantly improves the File Uploads guide with prominent warnings about memory buffering and detailed manual validation examples. The Learning Path curriculum is refined to better scaffold validation concepts by connecting Module 5 (Validation) back to Module 3's User Registry project. An internal documentation coverage map is also introduced for tracking feature documentation status.

Changes:

  • New Security Headers recipe with practical examples for production-ready HTTP security headers
  • Enhanced File Uploads guide emphasizing buffering limitations and manual validation requirements
  • Refined Learning Path to create better progression from basic handlers to validated endpoints
  • Added documentation coverage tracking for internal maintenance

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
docs/cookbook/src/recipes/security_headers.md New recipe covering SecurityHeadersLayer with basic, strict, and custom configurations
docs/cookbook/src/recipes/file_uploads.md Added buffering warnings, manual validation section, and corrected body_limit usage
docs/cookbook/src/recipes/advanced_middleware.md Added reverse proxy IP extraction documentation for RateLimitLayer
docs/cookbook/src/learning/curriculum.md Enhanced Module 5 with mini-project and linked it to Module 3's User Registry
docs/cookbook/src/SUMMARY.md Added Security Headers recipe to table of contents
docs/.agent/run_report_2026-02-24.md Internal run report documenting changes made
docs/.agent/last_run.json Updated tracking metadata
docs/.agent/docs_coverage.md Comprehensive feature-to-documentation mapping table

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

RustApi::new()
// Increase body limit to 1GB (default is usually 1MB)
.body_limit(1024 * 1024 * 1024)
// Increase body limit to 50MB (default is 2MB)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default body limit is 1MB (1024 * 1024 bytes), not 2MB. This is confirmed in the codebase at crates/rustapi-core/src/middleware/body_limit.rs:28 where DEFAULT_BODY_LIMIT is set to 1024 * 1024. Update this comment to reflect the correct default value.

Suggested change
// Increase body limit to 50MB (default is 2MB)
// Increase body limit to 50MB (default is 1MB = 1024 * 1024 bytes)

Copilot uses AI. Check for mistakes.

### Configuration

You must explicitly increase the body limit for any upload route, as the default is 2MB to prevent DoS attacks.
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default body limit is 1MB, not 2MB. According to crates/rustapi-core/src/middleware/body_limit.rs:28, DEFAULT_BODY_LIMIT is set to 1024 * 1024 bytes (1MB). Update this to state "default is 1MB" for accuracy.

Suggested change
You must explicitly increase the body limit for any upload route, as the default is 2MB to prevent DoS attacks.
You must explicitly increase the body limit for any upload route, as the default is 1MB to prevent DoS attacks.

Copilot uses AI. Check for mistakes.

```rust
use rustapi_rs::prelude::*;
use rustapi_rs::extract::{Multipart, DefaultBodyLimit};
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import DefaultBodyLimit is incorrect. This type does not exist in the rustapi-core crate. Since the code no longer uses DefaultBodyLimit::max(...) (which was correctly removed), this import should also be removed from the use statement.

Copilot uses AI. Check for mistakes.
Comment on lines +82 to 88
// Never trust the user-provided filename directly!
let safe_filename = format!("{}-{}", uuid::Uuid::new_v4(), file_name);
let path = Path::new("./uploads").join(&safe_filename);

// 3. Save to Disk
tokio::fs::write(&path, &data).await.map_err(|e| ApiError::internal(e.to_string()))?;

Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated safe_filename still incorporates the untrusted file_name directly, which may contain sequences like ../ or path separators. When combined with Path::new("./uploads").join(&safe_filename), an attacker can craft filenames such that .. segments escape the intended ./uploads directory and overwrite or create files elsewhere on the filesystem (path traversal). To avoid this, either completely reject path separators/.. in file_name or ignore the client-provided name for the on-disk path (e.g., use only a server-generated identifier and store the original name separately in metadata).

Copilot uses AI. Check for mistakes.
@Tuntii Tuntii closed this Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant