Here is the combined list of vulnerabilities in markdown format, with duplicates removed:
- Description: An attacker can craft a malicious SQL query that, when displayed in the Silk UI, executes arbitrary JavaScript code in the victim's browser. This is possible because the SQL query content is not properly sanitized before being displayed in the SQL detail view. An administrator viewing the Silk UI could be compromised if a malicious SQL query is logged.
Steps to trigger:
- An attacker needs to trigger the logging of a malicious SQL query.
- The malicious SQL query string should contain JavaScript code disguised within the query.
- An administrator logs into the Silk UI and navigates to the SQL detail view for the request that triggered the malicious query.
- When the SQL detail page renders, the unsanitized malicious SQL query is displayed, and the JavaScript code embedded within it is executed in the administrator's browser.
- Impact: Cross-Site Scripting (XSS). If an administrator views the malicious SQL query, arbitrary JavaScript code can be executed in their browser within the context of the Silk UI. This could lead to session hijacking, account takeover, or other malicious actions performed on behalf of the administrator.
- Vulnerability Rank: High
- Currently Implemented Mitigations: None
- Missing Mitigations: Implement output sanitization/escaping in the template
silk/templates/silk/sql_detail.html
forsql_query.formatted_query
. - Preconditions: Django-silk is installed and enabled in a Django project. An attacker can somehow cause a malicious SQL query to be logged by django-silk. An administrator with access to the Silk UI views the SQL detail page containing the malicious query.
- Source Code Analysis: Template
silk/templates/silk/sql_detail.html
renderssql_query.formatted_query
without any sanitization.sql_query.formatted_query
is obtained fromsqlparse.format(self.query, reindent=True, keyword_case='upper')
insilk/models.py
, which does not sanitize HTML characters. - Security Test Case:
- Craft a malicious SQL query string containing JavaScript code:
SELECT '<img src=x onerror=alert(\'XSS\')>' AS malicious_query;
- Execute this malicious SQL query in the monitored Django application to ensure it gets logged by django-silk.
- Log in to the Silk UI as an administrator.
- Navigate to the "Requests" view in the Silk UI.
- Find the request that corresponds to the execution of the malicious SQL query.
- Click on the request to view its details and then go to the "SQL" tab.
- Click on the SQL query to view its details.
- Observe that an alert box appears in your browser, confirming the XSS vulnerability.
- Craft a malicious SQL query string containing JavaScript code:
- Description: An attacker could potentially inject malicious JavaScript code within the raw request or response body of an HTTP request handled by the monitored application. If an administrator views the raw body in the Silk UI, this JavaScript code could be executed in their browser due to insufficient sanitization of the raw body content before rendering in the
silk/raw.html
template. Steps to trigger:- An attacker needs to send a request to the monitored application with a malicious JavaScript payload embedded in the request body or trigger a response with a malicious payload.
- The malicious JavaScript code should be embedded within the raw body.
- An administrator logs into the Silk UI and navigates to the request detail view.
- The administrator views the raw request or response body by navigating to the "Raw" tab.
- When the raw body is rendered in
silk/raw.html
, and if it's unsanitized, the JavaScript code is executed.
- Impact: Cross-Site Scripting (XSS). If an administrator views the raw request or response body containing malicious JavaScript, arbitrary JavaScript code can be executed in their browser within the context of the Silk UI, potentially leading to session hijacking, account takeover.
- Vulnerability Rank: High
- Currently Implemented Mitigations: Unknown. Assumed none.
- Missing Mitigations: Implement output sanitization/escaping in
silk/templates/silk/raw.html
for thebody
variable. - Preconditions: Django-silk is installed and enabled. An attacker can inject malicious JavaScript into the raw request or response body. An administrator with access to the Silk UI views the raw body.
- Source Code Analysis: The
Raw
view insilk/views/raw.py
passes thebody
variable tosilk/raw.html
without sanitization. Assumingsilk/raw.html
rendersbody
directly without sanitization. - Security Test Case:
- Craft a malicious JS payload in the response body, e.g., a JSON response:
{"data": "<img src=x onerror=alert('XSS_RAW_BODY')>"}
. - Trigger a request to an endpoint in the monitored application that returns this malicious response.
- Log in to the Silk UI as an administrator.
- Navigate to the "Requests" view.
- Find the request corresponding to the endpoint returning the malicious response.
- Click on the request to view details and go to the "Raw" tab.
- Select 'response' and 'raw' in the dropdowns.
- Observe if an alert box appears, confirming XSS in raw body display.
- Craft a malicious JS payload in the response body, e.g., a JSON response:
- Vulnerability Name: Unauthenticated Access to Profiling and Inspection Interface
- Description: An external attacker can directly navigate to any Silk UI endpoint (by default mounted under “/silk/”) without any authentication. An attacker can view detailed profiling data including intercepted HTTP requests and responses, database queries (with timings and even the raw SQL), request headers (which may include sensitive cookies or API tokens) and even sampled stack traces.
- Impact: Attackers may learn internal data about application logic, database structure and query performance, helping them refine further attacks such as targeted injections or remote code execution exploits.
- Vulnerability Rank: High
- Currently Implemented Mitigations:
- Optional configuration settings (e.g.
SILKY_AUTHENTICATION
andSILKY_AUTHORISATION
) exist in the Silk config. - Authentication/authorisation decorators (e.g.
login_possibly_required
) are present in the codebase but are no‑ops when the corresponding flags are disabled.
- Optional configuration settings (e.g.
- Missing Mitigations:
- By default, both authentication and authorisation for the Silk UI are disabled.
- No built‑in CSRF protection or enforced access control exists unless developers explicitly enable these settings.
- Preconditions: The application is deployed in a publicly accessible environment with the default Silk settings (debug/profiling enabled and no authentication).
- Source Code Analysis:
- The README and configuration documents state that “by default anybody can access the Silk user interface by heading to
/silk/
.” - In
silk/middleware.py
and various view modules (e.g.silk/views/summary.py
), the authentication decorators are implemented as pass‑through functions unless the settings flags are turned on.
- The README and configuration documents state that “by default anybody can access the Silk user interface by heading to
- Security Test Case:
- Using an external HTTP client (such as cURL or a web browser), send a GET request to an endpoint under
/silk/
(for example,http://<target_host>/silk/
). - Verify that the response returns the Silk summary page or other sensitive profiling details (headers, SQL timings, etc.) without any authentication prompt.
- Repeat for endpoints like
/silk/request/<uuid>/
and/silk/cleardb/
to confirm that no access control is enforced.
- Using an external HTTP client (such as cURL or a web browser), send a GET request to an endpoint under
- Vulnerability Name: Unauthenticated Access to Administrative Data Deletion Endpoint
- Description: The Silk project provides a “clear DB” view (mounted at “/silk/cleardb/”) which allows an administrator to purge all logged requests and profiling data. By default this endpoint is unprotected, and an attacker who discovers it may submit a POST request to delete critical diagnostic and forensic data.
- Impact: An attacker could sabotage system diagnostics and security investigations by wiping out historical logs, making it harder to detect and analyze more severe attacks later.
- Vulnerability Rank: High
- Currently Implemented Mitigations:
- The view uses optional authentication/authorisation wrappers (via decorators like
login_possibly_required
) that only enforce checks when configuration flags are enabled.
- The view uses optional authentication/authorisation wrappers (via decorators like
- Missing Mitigations:
- With the default configuration (
SILKY_AUTHENTICATION
andSILKY_AUTHORISATION
off), no authentication check is performed. - No additional confirmation prompt or audit logging exists to help prevent inadvertent or malicious deletion of log data.
- With the default configuration (
- Preconditions: The application is deployed with the default Silk settings in a production or publicly accessible environment, leaving the “/silk/cleardb/” endpoint fully open.
- Source Code Analysis:
- In
silk/views/clear_db.py
, the GET handler displays a confirmation page and the POST handler checks for a simple form field (e.g.clear_all=on
), then deletes data from multiple models without verifying the user’s identity. - The authentication decorators are no‑ops when the related settings are not enabled.
- In
- Security Test Case:
- Using an HTTP client, send a POST request to
http://<target_host>/silk/cleardb/
with the form parameterclear_all=on
. - Confirm that the response indicates the Silk logging data has been deleted.
- Optionally, verify via the Silk UI or the database that the log records have been cleared.
- Using an HTTP client, send a POST request to
- Vulnerability Name: Debug Mode Enabled in Production
- Description: The Django application’s settings (in
/code/project/project/settings.py
) specifyDEBUG = True
andDEBUG_PROPAGATE_EXCEPTIONS = True
. When deployed in production, these settings cause detailed error pages—including stack traces and sensitive configuration data—to be shown when errors occur. An external attacker can deliberately trigger errors (for example, by accessing non-existent URLs) to obtain internal system details. - Impact: Detailed disclosure of internal application state, configuration settings, and potentially sensitive data (such as database credentials and the secret key) can facilitate targeted attacks including session forgery, remote code execution, and privilege escalation.
- Vulnerability Rank: High
- Currently Implemented Mitigations: None; the default settings hardcode
DEBUG = True
for development purposes. - Missing Mitigations:
- In production,
DEBUG
should be set toFalse
andDEBUG_PROPAGATE_EXCEPTIONS
adjusted accordingly. - Use environment variables or dedicated configuration management to ensure production settings do not expose sensitive information.
- In production,
- Preconditions: The application is deployed using the project’s default settings, leaving it in development mode in a publicly accessible environment.
- Source Code Analysis:
- In
/code/project/project/settings.py
, the valuesDEBUG = True
andDEBUG_PROPAGATE_EXCEPTIONS = True
are explicitly set. - This configuration ensures that any unhandled exception will render a detailed debug page with stack traces and internal data.
- In
- Security Test Case:
- Deploy the application with the default settings.
- Use a web browser or HTTP client (like cURL) to deliberately trigger an error (e.g., request a non-existent URL such as
http://<target_host>/nonexistent
). - Examine the returned error page and verify that it contains detailed debug information including stack traces, configuration variables, and possibly the SECRET_KEY.
- Confirm that this sensitive information is exposed to the attacker.
- Vulnerability Name: Hard-Coded Secret Key in Application Settings
- Description: The application’s settings file (
/code/project/project/settings.py
) defines a fixedSECRET_KEY
that is embedded directly in the source code. If this key is ever exposed—especially via debug error pages whenDEBUG = True
—an attacker could use it to forge session cookies, tamper with cryptographic signatures, and bypass security controls. - Impact: Exposure of the hard-coded secret key can allow an attacker to impersonate users (by forging cookies or tokens) and compromise session integrity, which might lead to unauthorized actions or access escalation.
- Vulnerability Rank: High
- Currently Implemented Mitigations: There are no runtime safeguards to protect the embedded secret key; it is stored in the settings file and committed to source control.
- Missing Mitigations: The secret key should not be hard-coded. Instead, it should be injected via secure external sources such as environment variables or a secrets management service.
- Preconditions: The application must be deployed using the default settings, and debug mode (or similar functionality) must allow internal configuration details (including the SECRET_KEY) to be revealed during error conditions.
- Source Code Analysis:
- In
/code/project/project/settings.py
, theSECRET_KEY
is defined as:SECRET_KEY = 'ey5!m&h-uj6c7dzp@(o1%96okkq4!&bjja%oi*v3r=2t(!$7os'
This hard-coded key is permanently stored in the source code with no alternative configuration mechanism.
- In
- Security Test Case:
- Deploy the application with the provided settings.
- Trigger an application error (for example, by accessing a non-existent URL) that causes the debug error page to be displayed.
- Inspect the error page to verify whether the
SECRET_KEY
is visible in the configuration details. - Optionally, attempt to use the disclosed key to craft forged session cookies and determine if the application accepts them as valid.
-
Vulnerability Name: Local File Inclusion in SQL and Profile Detail Views
-
Description:
- An attacker can access the Silk UI, assuming authentication and authorization are either disabled or bypassed.
- The attacker navigates to the SQL detail view for any captured SQL query (e.g.,
/silk/request/<request_id>/sql/<sql_id>/
) or the Profile detail view for any captured profile (e.g.,/silk/profile/<profile_id>/
). - In both SQL and Profile detail views, the traceback might be displayed with file paths. These file paths are made clickable by the
filepath_urlify
template filter, pointing to the respective detail view but withfile_path
andline_num
parameters in the URL. - An attacker can manually craft a URL to either the SQL or Profile detail view, adding
file_path
andline_num
GET parameters with arbitrary file paths on the server. - The application, in
silk/views/code.py
's_code
function, directly opens and reads the file specified by thefile_path
parameter without any validation or sanitization. This function is called by bothsilk/views/sql_detail.py
'sSQLDetailView
andsilk/views/profile_detail.py
'sProfilingDetailView
. - The content of the file is then displayed in the respective detail view within the "Code" section.
-
Impact: An external attacker can read arbitrary files from the server's filesystem that the Django application has read permissions to. This could include sensitive source code, configuration files, data files, or environment variables, potentially leading to full server compromise or data breaches.
-
Vulnerability Rank: High
-
Currently Implemented Mitigations: None. The application directly opens and reads files based on user-provided input without validation in both SQL and Profile detail views.
-
Missing Mitigations:
- Input validation and sanitization for the
file_path
parameter insilk/views/code.py
's_code
function,silk/views/sql_detail.py
'sSQLDetailView
, andsilk/views/profile_detail.py
'sProfilingDetailView
. - Implement proper access control to the Silk UI to restrict access to authorized users only. Enabling
SILKY_AUTHENTICATION
andSILKY_AUTHORISATION
settings and configuringSILKY_PERMISSIONS
to restrict access to staff or superuser accounts is crucial.
- Input validation and sanitization for the
-
Preconditions:
- Silk is installed and enabled in a Django project.
- The Silk UI is accessible to the attacker (either
SILKY_AUTHENTICATION
andSILKY_AUTHORISATION
are disabled, or the attacker has bypassed authentication/authorization). - For SQL detail view: There must be at least one SQL query captured by Silk to access the SQL detail view initially and obtain a valid URL structure to modify.
- For Profile detail view: There must be at least one profile captured by Silk to access the Profile detail view initially and obtain a valid URL structure to modify.
-
Source Code Analysis:
-
File: /code/silk/views/sql_detail.py
from silk.views.code import _code class SQLDetailView(View): # ... def get(self, request, *_, **kwargs): # ... file_path = request.GET.get('file_path', '') line_num = int(request.GET.get('line_num', 0)) # ... if pos and file_path and line_num: actual_line, code = _code(file_path, line_num) # [!] file_path from request.GET is passed directly to _code context['code'] = code context['actual_line'] = actual_line return render(request, 'silk/sql_detail.html', context)
The
SQLDetailView
retrieves thefile_path
parameter directly from the GET request and passes it to the_code
function. -
File: /code/silk/views/profile_detail.py
from silk.views.code import _code_context, _code_context_from_request ... class ProfilingDetailView(View): # ... def get(self, request, *_, **kwargs): # ... context['pos'] = pos = int(request.GET.get('pos', 0)) if pos: context.update(_code_context_from_request(request, prefix='pyprofile_')) # [!] Calls _code_context_from_request which uses _code ... if file_path and line_num: try: context.update(_code_context(file_path, line_num, profile.end_line_num)) # [!] Calls _code_context which uses _code except OSError as e: ...
The
ProfilingDetailView
also uses_code_context_from_request
and_code_context
, both of which eventually call the vulnerable_code
function with user-controlledfile_path
. -
File: /code/silk/views/code.py
from silk.config import SilkyConfig def _code(file_path, line_num, end_line_num=None): # ... with open(file_path, encoding='utf-8') as f: # [!] file_path is opened without validation # ... for i, line in enumerate(f): if i in r: lines += line if i + 1 in range(line_num, end_line_num + 1): actual_line.append(line) code = lines.split('\n') return actual_line, code
The
_code
function directly uses thefile_path
argument inopen(file_path, encoding='utf-8')
without any validation. -
Visualization:
graph LR A[User crafts malicious URL with file_path (SQL or Profile Detail)] --> B(SQLDetailView.get / ProfilingDetailView.get); B --> C{request.GET.get('file_path')}; C -- file_path --> D[_code(file_path, line_num)]; D --> E{open(file_path)}; E --> F[Read arbitrary file content]; F --> G(Display file content in Detail View); G --> H[Attacker views content];
-
-
Security Test Case:
- Deploy a Django application with django-silk installed and configured (ensure
SILKY_AUTHENTICATION
andSILKY_AUTHORISATION
are disabled for easy testing, but in a real-world scenario, test after bypassing authentication). - Trigger any Django view that executes at least one SQL query and one profile to ensure there is data in Silk.
- Access the Silk UI (e.g.,
/silk/
). - For SQL Detail View:
a. Navigate to the "Requests" tab and select any request.
b. Go to the "SQL" tab for the selected request and click on any SQL query to view its details. This will lead you to the SQL detail view (e.g.,
/silk/request/<request_id>/sql/<sql_id>/
). c. Observe the URL of the SQL detail page. It should look something like/silk/request/<request_id>/sql/<sql_id>/
. d. Manually modify the URL by adding thefile_path
andline_num
parameters. For example, to attempt to read/etc/passwd
, construct a URL like:/silk/request/<request_id>/sql/<sql_id>/?file_path=/etc/passwd&line_num=1
. e. Access the crafted URL in your browser. f. Check the "Code" section in the SQL detail view. If the vulnerability exists, you should see the content of the/etc/passwd
file (or any other file you attempted to read, assuming the Django application has read permissions). If you are testing on Windows, try to readC:\Windows\win.ini
for example. g. If the file content is displayed, the Local File Inclusion vulnerability is confirmed in SQL detail view. - For Profile Detail View:
a. Navigate to the "Profiling" tab and select any profile. This will lead you to the Profile detail view (e.g.,
/silk/profile/<profile_id>/
). b. Observe the URL of the Profile detail page. It should look something like/silk/profile/<profile_id>/
. c. Manually modify the URL by adding thefile_path
andline_num
parameters. For example, to attempt to read/etc/passwd
, construct a URL like:/silk/profile/<profile_id>/?file_path=/etc/passwd&line_num=1
. d. Access the crafted URL in your browser. e. Check the "Code" section in the Profile detail view. If the vulnerability exists, you should see the content of the/etc/passwd
file (or any other file you attempted to read, assuming the Django application has read permissions). If you are testing on Windows, try to readC:\Windows\win.ini
for example. f. If the file content is displayed, the Local File Inclusion vulnerability is confirmed in Profile detail view. - If the file content is displayed in either SQL or Profile detail view, the Local File Inclusion vulnerability is confirmed.
- Deploy a Django application with django-silk installed and configured (ensure