Skip to content

CAP Framework Modeling Gaps #264

@data-douser

Description

@data-douser

Summary

This issue tracks identified gaps in CodeQL library modeling and security queries for the SAP Cloud Application Programming (CAP) framework. Analysis is based on the CAP framework documentation, existing implementation in javascript/frameworks/cap/, and review of merged CAP PRs and merged CDS PRs.

Identified Gaps

Authentication & Authorization Patterns

  • JWT token validation and propagation - Model req.user.token, JWT validation flows, and token forwarding in service-to-service calls
  • Session management - Model req.user.id, req.user.attr, and session-based authentication patterns
  • OAuth/XSUAA flows - Model authentication strategies beyond what's in NonProductionStrategyUsed.ql
  • User propagation - Track user context propagation in distributed CAP services

Draft Handling

  • Draft editing operations - Model @odata.draft.enabled entity annotations and draft state transitions
  • Draft activation/discard - Model draft-specific event handlers (DraftPrepare, DraftActivate, DraftDiscard)
  • Draft isolation - Understand security implications of draft data isolation

Transaction Management

  • Transaction context tracking - Model cds.tx() and transaction boundary creation
  • Commit/rollback patterns - Track transaction lifecycle and error handling
  • Nested transactions - Model sub-transaction contexts and their security implications

OData Protocol Features

  • Query parameter injection - Model $filter, $orderby, $expand, $select parameters as potential injection points
  • OData aggregation - Model aggregation queries and potential information leakage
  • Batch operations - Model $batch endpoint processing and batch request parsing
  • OData metadata exposure - Track sensitive information in $metadata endpoints

CAP-Specific Data Operations

  • Association navigation - Model taint propagation through entity associations and compositions
  • Deep insert/update - Track nested entity modifications and cascading operations
  • Virtual entities - Model remote service entities and their data flow
  • Custom actions and functions - Model bound/unbound actions defined in .cds files

CDS Annotations Security

  • Validation annotations - Model @assert.range, @assert.format, @mandatory for sanitization
  • @readonly enforcement - Detect violations of read-only annotations
  • @cds.on.insert/@cds.on.update - Model annotation-based lifecycle hooks
  • Personal data annotations - Model @PersonalData, @PersonalData.IsPotentiallySensitive for privacy compliance

Advanced Data Flow

  • File upload handling - Model multipart/form-data processing and file attachment flows
  • Streaming operations - Model large binary data streams (sources and sinks)
  • Custom middleware - Track custom Express middleware registration and request/response modification
  • Error handler taint - Model custom error handlers and error message leakage
  • Background jobs - Model asynchronous job processing (cds.spawn, messaging)

Database-Specific Patterns

  • HANA-specific features - Model HANA calculation views, stored procedures, and SQL Script
  • Native SQL execution - Model cds.run(), cds.db.run() with raw SQL
  • Database function calls - Model database-specific function calls (e.g., HANA functions)

Messaging & Events

  • Message queue sources - Model CAP messaging (emit/on patterns for message brokers)
  • Event mesh integration - Model SAP Event Mesh as external event sources
  • Cross-service events - Track event propagation across CAP services

API Gateway & BTP Integration

  • API Management policies - Consider API Gateway transformations affecting taint
  • Destination service - Model destination configuration as potential credential exposure
  • Cloud Connector - Model on-premise connectivity as additional attack surface

Completed Work

Recent CAP modeling enhancements (see merged PRs):

Query Enhancements:

Modeling Improvements:

Framework-Specific Configuration:

CDS Extractor Enhancements:

Currently Modeled:

  • Event handlers: srv.on, srv.before, srv.after
  • Remote flow sources: req.data, req.params, req.headers, req.id, req._queryOptions, req.http.req.*
  • Service patterns: ES6 class extension, cds.service.impl(), exported closure
  • Service exposure: @path annotation detection, protocol: 'none' filtering
  • CQL fluent API: SELECT, INSERT, UPDATE, DELETE, UPSERT
  • CDS annotations: @restrict, @requires (for authorization)
  • CDS definition parsing: entities, events, actions, functions

Implementation Notes

For new gaps:

  1. Follow Test-Driven Development methodology
  2. Reference CAP framework development prompt for detailed patterns
  3. Use javascript-cap-modeling-agent for implementation
  4. Consult CAP documentation for authoritative behavior
  5. Add tests to javascript/frameworks/cap/test/ with .expected files

Priority should be given to gaps that:

  • Are commonly exploited in CAP applications
  • Have high impact on security posture
  • Are currently not detected by out-of-box CodeQL queries

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions