Skip to content

Conversation

lorakste
Copy link
Contributor

@lorakste lorakste commented Mar 30, 2025

Fixed an issue where the average CVSS score calculation was incorrect due to improper access to the findings key within the JSON structure. The calculation logic was bypassing the findings key and therefore failing to extract valid CVSS scores.

Describe the Pull Request

This PR fixes a bug where the average CVSS score calculation would always return 0  due to improper JSON traversal.

Checklist for PR

  • Run MobSF unit tests and lint tox -e lint,test
  • Tested Working on Linux, Mac, Windows, and Docker
  • Add unit test for any new Web API (Refer: StaticAnalyzer/tests.py)
  • Make sure tests are passing on your PR MobSF tests

Additional Comments (if any)

DESCRIBE HERE

Fixed an issue where the average CVSS score calculation was incorrect due to improper access to the findings key within the JSON structure. The calculation logic was bypassing the findings key and therefore failing to extract valid CVSS scores.
@ajinabraham
Copy link
Member

Thanks for the PR, I will review this and get back.

@ajinabraham ajinabraham requested a review from Copilot April 24, 2025 16:39
Copy link
Contributor

@Copilot 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 pull request fixes the bug in the average CVSS score calculation by ensuring the correct extraction of the CVSS scores from the JSON structure.

  • Modified the CVSS calculation by passing the 'findings' key from code_analysis to get_avg_cvss
  • Updated both dynamic context functions (for APK and source code analysis) to reflect the fix


def generate_dynamic_context(request, app_dic, checksum, context, api):
"""Generate Dynamic Context."""
context['appsec'] = get_android_dashboard(context, True)
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

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

The updated call correctly accesses the 'findings' key to retrieve the necessary CVSS scores. Consider adding a brief inline comment to document the expected JSON structure for future maintenance.

Suggested change
context['appsec'] = get_android_dashboard(context, True)
context['appsec'] = get_android_dashboard(context, True)
# The 'code_analysis' key in the context is expected to contain a 'findings' key,
# which holds a list of CVSS scores used to calculate the average CVSS.

Copilot uses AI. Check for mistakes.

Comment on lines +368 to 369
context['average_cvss'] = get_avg_cvss(context['code_analysis']['findings'])
template = 'static_analysis/android_source_analysis.html'
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

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

This change properly extracts the CVSS scores from the 'findings' key. A short inline note explaining why the 'findings' key is used could aid future maintainers.

Suggested change
context['average_cvss'] = get_avg_cvss(context['code_analysis']['findings'])
template = 'static_analysis/android_source_analysis.html'
# The 'findings' key in 'context['code_analysis']' contains the results of the code analysis,
# including CVSS scores. It is used here to calculate the average CVSS score.
findings = context['code_analysis'].get('findings', None)
context['average_cvss'] = get_avg_cvss(findings) if findings else None

Copilot uses AI. Check for mistakes.

@ajinabraham ajinabraham merged commit df9c53d into MobSF:master Apr 24, 2025
2 checks passed
J1-MI pushed a commit to J1-MI/OMT_Semi_project2_MobSF that referenced this pull request Sep 9, 2025
Fixed an issue where the average CVSS score calculation was incorrect due to improper access to the findings key within the JSON structure. The calculation logic was bypassing the findings key and therefore failing to extract valid CVSS scores.

Co-authored-by: Ajin Abraham <[email protected]>
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.

2 participants