-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
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.enabledentity 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,$selectparameters as potential injection points - OData aggregation - Model aggregation queries and potential information leakage
- Batch operations - Model
$batchendpoint processing and batch request parsing - OData metadata exposure - Track sensitive information in
$metadataendpoints
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
.cdsfiles
CDS Annotations Security
- Validation annotations - Model
@assert.range,@assert.format,@mandatoryfor sanitization -
@readonlyenforcement - Detect violations of read-only annotations -
@cds.on.insert/@cds.on.update- Model annotation-based lifecycle hooks - Personal data annotations - Model
@PersonalData,@PersonalData.IsPotentiallySensitivefor 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:
- CQL Injection query with template literal and concatenation patterns (Begin dataflow lib upgrade generic portions #220)
- Log Injection query with interprocedural tracking and conservative type handling (Make CAP Log injection query more resilient and conservative #226)
- Path Injection query for
cds.utilsfile operations (Add CDS Utils path injection query #224) - Sensitive Data Exposure split query using out-of-box sources (Add sensitive exposure split query #207)
- Authentication/Authorization queries (DefaultUserIsPrivileged, UnnecessarilyGrantedPrivilegedAccessRights, NonProductionStrategyUsed, EntityExposedWithoutAuthn)
Modeling Improvements:
- 3 service definition patterns including exported closure (Address FN involving CAP remote flow sources #222)
- Restricted remote flow sources to property reads (Restrict
RemoteFlowSourceof CAP to only some properties and method calls on it #208) - CDS utils modeling for file system operations (Add cds utils modelling #206)
- Enhanced remote flow sources with fallback for missing CDS definitions (Enhance remote flow sources for CAP #201)
Framework-Specific Configuration:
- Separated CAP taint configs from default configs (Remove dependencies on
isSinkin the taint tracking configurations of the default queries #180) - Type-based barriers to exclude non-String injection alerts (Exclude injection alerts where the input data type is not String #115)
CDS Extractor Enhancements:
- Source-relative file paths in diagnostics (Fix CDS extractor database diagnostics to point to source-relative file paths #239)
- Retry mechanism for compilation failures (CDS extractor : Implement retry for CDS compilation tasks #209)
- Performance optimization for
getCdsDeclaration()(Address a performance regression in recent upgrade #177) - Fixed
cds compilecommand usage (Runcds compilecommand without-ooption #172) - Dataflow API migration to non-deprecated APIs (Bump
codeql/javascript-alland fix breaking changes #170)
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:
@pathannotation 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:
- Follow Test-Driven Development methodology
- Reference CAP framework development prompt for detailed patterns
- Use javascript-cap-modeling-agent for implementation
- Consult CAP documentation for authoritative behavior
- Add tests to
javascript/frameworks/cap/test/with.expectedfiles
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
Labels
No labels