-
Notifications
You must be signed in to change notification settings - Fork 0
Add Flask web service with shipping and transaction APIs #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,20 @@ | |
| """ | ||
| Maritime Demo Application | ||
| A simple hello world application with external dependencies | ||
| Now includes a Flask web service for shipping logistics | ||
| """ | ||
|
|
||
| import requests | ||
| from datetime import datetime | ||
| from colorama import Fore, Style, init | ||
| from flask import Flask, jsonify, request | ||
|
|
||
| # Initialize colorama | ||
| init() | ||
|
|
||
| # Initialize Flask app | ||
| app = Flask(__name__) | ||
|
|
||
| def main(): | ||
| """Main application entry point""" | ||
| # print(f"{Fore.CYAN}=" * 50) | ||
|
|
@@ -37,6 +42,73 @@ | |
|
|
||
| print(f"{Fore.LIGHTCYAN_EX}=" * 50) | ||
| print(f"{Fore.LIGHTCYAN_EX}=" * 50) | ||
|
|
||
| @app.route('/health') | ||
| def health(): | ||
| """Health check endpoint for maritime services""" | ||
| return jsonify({ | ||
| 'status': 'healthy', | ||
| 'service': 'maritime-logistics', | ||
| 'timestamp': datetime.now().isoformat() | ||
| }) | ||
|
|
||
| @app.route('/api/shipping/track/<tracking_id>') | ||
| def track_shipment(tracking_id): | ||
| """ | ||
| Track shipment by calling external shipping API | ||
| Uses requests library to communicate with third-party services | ||
| VULNERABLE: Uses requests 2.25.0 which has CVE-2024-47081 | ||
| """ | ||
| try: | ||
| # Simulate calling external shipping API | ||
| # This demonstrates reachability - the vulnerable requests library is actively used | ||
| api_url = f"https://api.shipping-service.example.com/track/{tracking_id}" | ||
| response = requests.get(api_url, timeout=5) | ||
|
|
||
| return jsonify({ | ||
| 'tracking_id': tracking_id, | ||
| 'status': 'success', | ||
| 'message': 'Shipment tracking data retrieved' | ||
| }) | ||
| except Exception as e: | ||
| return jsonify({ | ||
| 'tracking_id': tracking_id, | ||
| 'status': 'error', | ||
| 'message': str(e) | ||
| }), 500 | ||
|
|
||
| @app.route('/api/verify/transaction', methods=['POST']) | ||
| def verify_transaction(): | ||
| """ | ||
| Verify banking transaction by calling external verification service | ||
| VULNERABLE: Uses requests library with CVE-2024-47081 | ||
| This is a critical path for financial transactions | ||
| """ | ||
| try: | ||
| data = request.get_json() | ||
| transaction_id = data.get('transaction_id') | ||
|
|
||
| # Call external banking verification API | ||
| # This uses the vulnerable requests library - demonstrating reachability | ||
| verification_url = "https://api.banking-verify.example.com/verify" | ||
| response = requests.post(verification_url, json=data, timeout=10) | ||
|
|
||
| return jsonify({ | ||
| 'transaction_id': transaction_id, | ||
| 'verified': True, | ||
| 'timestamp': datetime.now().isoformat() | ||
| }) | ||
| except Exception as e: | ||
| return jsonify({ | ||
| 'error': str(e), | ||
| 'verified': False | ||
| }), 500 | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| # Can run as CLI app or web service | ||
| import sys | ||
| if len(sys.argv) > 1 and sys.argv[1] == 'web': | ||
| print(f"{Fore.GREEN}Starting Maritime Web Service...{Style.RESET_ALL}") | ||
| app.run(debug=True, host='0.0.0.0', port=5000) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗Cycode: SAST violation: 'Usage of Flask debug mode'. Severity: Medium DescriptionEnabling Flask's debug mode exposes sensitive internal information through detailed error messages, stack traces, and the interactive Werkzeug debugger. This can allow attackers to discover application internals, leak environment variables, or even execute arbitrary code. Cycode Remediation Guideline✅ Do
from flask import Flask
app = Flask(__name__)
app.run(debug=False)❌ Don't
from flask import Flask
app = Flask(__name__)
app.run(debug=True) # This should be avoided
📋 References |
||
| else: | ||
| main() | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| requests==2.31.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| requests==2.32.4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Flask==2.0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗Cycode: Security vulnerabilities found in newly introduced dependency.
The following vulnerabilities were introduced:
Highest fixed version: 2.2.5 DescriptionDetects when new vulnerabilities affect your dependencies. Tell us how you wish to proceed using one of the following commands:
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Jinja2==3.0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗Cycode: Security vulnerabilities found in newly introduced dependency.
The following vulnerabilities were introduced:
Highest fixed version: 3.1.6 DescriptionDetects when new vulnerabilities affect your dependencies. Tell us how you wish to proceed using one of the following commands:
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Werkzeug==2.0.3 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗Cycode: Security vulnerabilities found in newly introduced dependency.
The following vulnerabilities were introduced:
Highest fixed version: 3.0.6 DescriptionDetects when new vulnerabilities affect your dependencies. Tell us how you wish to proceed using one of the following commands:
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| colorama==0.4.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| python-dateutil==2.8.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| mcp>=1.0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗Cycode: SAST violation: 'Unsanitized user input in HTTP request (SSRF)'.
Severity: High
Description
Your application is vulnerable to Server-Side Request Forgery (SSRF) attacks when it connects to URLs that include user-supplied data. This vulnerability occurs because attackers can manipulate these URLs to force your application to make unintended requests to internal or external resources.
Cycode Remediation Guideline
✅ Do
❌ Don't
📋 References