Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iast): check secure marks in ranges before reporting vulnerabilities #13044

Merged
merged 58 commits into from
Apr 8, 2025

Conversation

avara1986
Copy link
Member

@avara1986 avara1986 commented Apr 3, 2025

This PR enhances IAST vulnerability detection by implementing secure mark validation before reporting vulnerabilities. The changes include:

  • Added core functionality for secure marks handling in taint ranges
  • Implemented secure mark validation for Command Injection (CMDI) vulnerabilities
  • Added support for secure mark validation in database operations (psycopg2)
  • Improved vulnerability reporting logic to consider secure marks
  • Added comprehensive test coverage for secure mark functionality

These changes improve the accuracy of vulnerability detection by ensuring that properly sanitized inputs (marked as secure) are not reported as vulnerabilities, reducing false positives in the IAST system.

Related to: APPSEC-56946 & APPSEC-57144

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@avara1986 avara1986 changed the title feat(iast): check secure marks in ranges before report the vulnerability feat(iast): check secure marks in ranges before reporting vulnerabilities Apr 3, 2025
Copy link
Contributor

github-actions bot commented Apr 3, 2025

CODEOWNERS have been resolved as:

ddtrace/appsec/_iast/secure_marks/__init__.py                           @DataDog/asm-python
ddtrace/appsec/_iast/secure_marks/sanitizers.py                         @DataDog/asm-python
ddtrace/appsec/_iast/secure_marks/validators.py                         @DataDog/asm-python
tests/appsec/iast/db_utils.py                                           @DataDog/asm-python
tests/appsec/iast/fixtures/secure_marks/__init__.py                     @DataDog/asm-python
tests/appsec/iast/fixtures/secure_marks/sanitizers.py                   @DataDog/asm-python
tests/appsec/iast/secure_marks/conftest.py                              @DataDog/asm-python
tests/appsec/iast/secure_marks/test_sanitizers.py                       @DataDog/asm-python
tests/appsec/iast/secure_marks/test_validators.py                       @DataDog/asm-python
tests/appsec/iast/test_iast_psycopg2.py                                 @DataDog/asm-python
tests/appsec/integrations/fixtures/patch_psycopg2.py                    @DataDog/asm-python
ddtrace/appsec/_iast/_ast/iastpatch.c                                   @DataDog/asm-python
ddtrace/appsec/_iast/_handlers.py                                       @DataDog/asm-python
ddtrace/appsec/_iast/_patch_modules.py                                  @DataDog/asm-python
ddtrace/appsec/_iast/_taint_tracking/taint_tracking/taint_range.cpp     @DataDog/asm-python
ddtrace/appsec/_iast/_taint_tracking/tests/test_secure_marks.cpp        @DataDog/asm-python
ddtrace/appsec/_iast/_taint_utils.py                                    @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/_base.py                               @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/code_injection.py                      @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/command_injection.py                   @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/header_injection.py                    @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/insecure_cookie.py                     @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/path_traversal.py                      @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/sql_injection.py                       @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/ssrf.py                                @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/weak_randomness.py                     @DataDog/asm-python
ddtrace/appsec/_iast/taint_sinks/xss.py                                 @DataDog/asm-python
ddtrace/contrib/dbapi.py                                                @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/dbapi_async.py                                          @DataDog/apm-core-python @DataDog/apm-idm-python
tests/appsec/iast/fixtures/taint_sinks/sql_injection_psycopg2.py        @DataDog/asm-python
tests/appsec/iast/taint_sinks/test_command_injection.py                 @DataDog/asm-python
tests/appsec/iast/taint_sinks/test_sql_injection.py                     @DataDog/asm-python
tests/appsec/iast/test_taint_utils.py                                   @DataDog/asm-python

@avara1986 avara1986 added changelog/no-changelog A changelog entry is not required for this PR. ASM Application Security Monitoring labels Apr 3, 2025
@pr-commenter
Copy link

pr-commenter bot commented Apr 3, 2025

Benchmarks

Benchmark execution time: 2025-04-08 10:27:41

Comparing candidate commit 1f4c41b in PR branch avara1986/APPSEC-56946_cmdi_secure_mark_check with baseline commit fd61a3b in branch main.

Found 1 performance improvements and 1 performance regressions! Performance is the same for 494 metrics, 2 unstable metrics.

scenario:iast_aspects-ospathdirname_aspect

  • 🟩 execution_time [-471.793ns; -395.340ns] or [-8.621%; -7.224%]

scenario:iast_aspects-ospathsplitdrive_aspect

  • 🟥 execution_time [+306.714ns; +361.295ns] or [+7.582%; +8.931%]

@avara1986 avara1986 marked this pull request as ready for review April 7, 2025 13:40
chojomok pushed a commit that referenced this pull request Apr 7, 2025
This PR reorganizes the SQL injection detection logic by moving it to
the IAST folder structure. The changes include:

- Relocated SQL injection detection code from contrib to
ddtrace/appsec/_iast/
- Consolidated SQL injection related functionality in a dedicated
location
- Improved code organization and maintainability
- Maintained existing functionality while improving code structure
- Updated imports and references to reflect new file locations

This refactoring aligns with our ongoing efforts to better organize
IAST-related code and makes the codebase more maintainable by grouping
related security features together.

No functional changes are included in this PR, it's purely
organizational.

Related to: #13044 and
APPSEC-56946

- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

- [x] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
@avara1986 avara1986 force-pushed the avara1986/APPSEC-56946_cmdi_secure_mark_check branch from 8008aa5 to 8bcd435 Compare April 7, 2025 18:59
@avara1986 avara1986 marked this pull request as draft April 7, 2025 20:29
@avara1986 avara1986 force-pushed the avara1986/APPSEC-56946_cmdi_secure_mark_check branch from 9df9d01 to a01965e Compare April 7, 2025 20:42
@avara1986 avara1986 mentioned this pull request Apr 8, 2025
2 tasks
@avara1986 avara1986 marked this pull request as ready for review April 8, 2025 08:23
@avara1986 avara1986 merged commit 46958d6 into main Apr 8, 2025
460 checks passed
@avara1986 avara1986 deleted the avara1986/APPSEC-56946_cmdi_secure_mark_check branch April 8, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASM Application Security Monitoring changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants