Skip to content

feat: add API documentation endpoint at root - #6

Merged
hitchho merged 1 commit into
masterfrom
claude/issue-5-20250621_094227
Jun 21, 2025
Merged

feat: add API documentation endpoint at root#6
hitchho merged 1 commit into
masterfrom
claude/issue-5-20250621_094227

Conversation

@hitchho

@hitchho hitchho commented Jun 21, 2025

Copy link
Copy Markdown
Contributor

Add comprehensive API information endpoint at "/" that returns:

  • Service description and version information
  • Complete documentation of all available endpoints
  • Request/response formats and parameters
  • cURL usage examples for each endpoint
  • Important notes about timeouts, caching, and file size limits

This provides users with a clear overview of how to use the Githem API for repository ingestion.

Fixes #5

Add comprehensive API information endpoint at "/" that returns:
- Service description and version information
- Complete documentation of all available endpoints
- Request/response formats and parameters
- cURL usage examples for each endpoint
- Important notes about timeouts, caching, and file size limits

This provides users with a clear overview of how to use the Githem API for repository ingestion.

Fixes #5

Co-authored-by: Tom Mi <hitchhooker@users.noreply.github.com>
@hitchho

hitchho commented Jun 21, 2025

Copy link
Copy Markdown
Contributor Author

/security review PR is it good to be merged? test it builds

@claude

claude Bot commented Jun 21, 2025

Copy link
Copy Markdown
Contributor

Claude finished @hitchhooker's task —— View job


🚨 Critical Security Issues Found

RECOMMENDATION: DO NOT MERGE - Multiple high-severity vulnerabilities discovered.

Todo List:

  • Read and analyze the changed code in api/src/http.rs
  • Check for common web security vulnerabilities
  • Test build process (requires bash permissions)
  • Provide security assessment and recommendations

Critical Security Vulnerabilities:

Issue: Information Disclosure - Detailed API reconnaissance
Line: api/src/http.rs:125-237
Fix: Remove or restrict access to the detailed API documentation endpoint
Example:

// Instead of exposing all internal details, provide minimal info
async fn api_info() -> impl IntoResponse {
    Json(serde_json::json!({
        "name": "Githem API",
        "version": env!("CARGO_PKG_VERSION"),
        "status": "operational"
        // Remove detailed endpoint mappings, examples, and system limits
    }))
}

Issue: No Authentication/Authorization - Anyone can consume resources
Line: api/src/http.rs:412-442
Fix: Implement API key or bearer token authentication
Example:

use axum::middleware;
use axum::extract::Request;

async fn auth_middleware(request: Request, next: Next) -> Result<Response, StatusCode> {
    // Validate API key from header
    match request.headers().get("x-api-key") {
        Some(key) => {
            // Validate key against allowed keys
            next.run(request).await
        }
        None => Err(StatusCode::UNAUTHORIZED)
    }
}

// Apply to router:
.route_layer(middleware::from_fn(auth_middleware))

Issue: CORS Misconfiguration enables CSRF attacks
Line: api/src/http.rs:439
Fix: Replace permissive CORS with restrictive policy
Example:

.layer(CorsLayer::new()
    .allow_origin("https://yourdomain.com".parse::<HeaderValue>().unwrap())
    .allow_methods([Method::GET, Method::POST])
    .allow_headers([CONTENT_TYPE]))

Issue: DoS via Resource Exhaustion - No rate limiting
Line: api/src/http.rs:252-297
Fix: Implement rate limiting middleware
Example:

use tower::limit::RateLimitLayer;
.layer(RateLimitLayer::new(10, Duration::from_secs(60))) // 10 req/min

Issue: Potential Path Traversal in wildcard routing
Line: api/src/http.rs:359-364
Fix: Add strict path validation
Example:

async fn handle_repo_path(
    Path((owner, repo, branch, path)): Path<(String, String, String, String)>,
    Query(params): Query<QueryParams>,
) -> Result<impl IntoResponse, AppError> {
    // Validate path doesn't contain traversal attempts
    if path.contains("..") || path.contains("//") {
        return Err(AppError::InvalidRequest("Invalid path".to_string()));
    }
    ingest_github_repo(owner, repo, Some(branch), Some(path), params).await
}

Issue: Cache timing attack potential
Line: api/src/http.rs:281-290
Fix: Use constant-time operations for cache cleanup

Issue: Missing Security Headers
Line: api/src/http.rs:431-438
Fix: Add comprehensive security headers
Example:

.layer(SetResponseHeaderLayer::overriding(
    header::CONTENT_SECURITY_POLICY,
    HeaderValue::from_static("default-src 'self'")
))
.layer(SetResponseHeaderLayer::overriding(
    header::STRICT_TRANSPORT_SECURITY,
    HeaderValue::from_static("max-age=31536000; includeSubDomains")
))

Build Status:

❌ Cannot test build - requires bash permissions in CI

Security Score: 🔴 CRITICAL

  • 7 security vulnerabilities identified (3 high, 3 medium, 1 low)
  • Critical infrastructure risk - service exposed without authentication
  • Immediate remediation required before deployment

@hitchho
hitchho merged commit bf6ed6f into master Jun 21, 2025
2 checks passed
@hitchho
hitchho deleted the claude/issue-5-20250621_094227 branch June 21, 2025 13:12
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.

we should return api info at root how its used

1 participant