Closes #22654: Redact install paths from debug tracebacks - #22655
Conversation
…bug field to superusers - `format_render_error()` now strips the absolute install-path prefix (everything up to but not including the repo root) from all `File "..."` lines in the traceback using `re.sub`, so internal filesystem layout is not exposed (CWE-209). - `ConfigTemplateForm.__init__` removes the `debug` field and its fieldset entry when the requesting user is not a superuser; `ConfigTemplateEditView` injects `request` via `functools.partial` before the base view instantiates the form. - `ConfigTemplateBulkEditForm.__init__` applies the same superuser gate; `ConfigTemplateBulkEditView.post()` injects `request` the same way. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion - ConfigTemplateSerializer.validate_debug() rejects debug=True from non-superusers with a 400 ValidationError, closing the API bypass left by the form-only gate. - Add ConfigTemplateFormSuperuserGateTestCase (test_forms.py) covering both model form and bulk edit form: superuser sees debug, non-superuser does not. - Add two tests to ConfigTemplateDebugTestCase (test_models.py): path redaction assertion (assertNotIn(install_root, result)) and concise-message assertion. - Add two API tests to ConfigTemplateTestCase (test_api.py): non-superuser PATCH debug=True yields 400; superuser PATCH debug=True yields 200. - Improve comments: note venv/stdlib path behavior in format_render_error(), document the field-absent-on-save behavior and InlineFields caveat in the form. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@claude /review and report only on areas of potential concern. |
|
Claude finished @bctiemann's task in 3m 43s —— View job PR Review: Redact install paths from debug tracebacks; restrict debug field to superusersTasks:
Areas of Potential Concern1. Incomplete Path Redaction — Venv and Stdlib Paths Remain Visible
install_root = os.path.dirname(settings.BASE_DIR) + os.sepThe regex strips only paths under
The comment in the code says venv paths are "under install_root (including the venv)", but a venv at 2.
|
…h tests - Also strip sys.prefix when running inside a venv whose root is outside install_root (typical production pattern: ~/.venv/netbox/), so the deployment user home directory is not disclosed via tracebacks. The check sys.prefix != sys.base_prefix avoids stripping system Python paths when not in a venv. - Update test_format_render_error_debug_redacts_install_path to assert venv_root is also absent from the redacted traceback when running inside a venv. - Add test_debug_false_allowed_for_non_superuser: validate_debug must not block non-superusers from setting debug=False. - Add test_debug_absent_from_payload_non_superuser: validate_debug must not fire when debug is absent from the PATCH payload, even if debug=True in the DB. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Addressed items 1 and 3. 2 and 4 are minor/below the bar for this fix. |
jeremystretch
left a comment
There was a problem hiding this comment.
The
debugfield is now restricted to superusers
This cannot be included in the scope of a bug fix, as it represents a change to intended functionality. It needs to be a separate FR. Please revert the related changes so that the PR is limited to the sanitization of file paths.
Restricting the debug field to superusers changes existing behavior for any user who currently has edit permission on ConfigTemplate, which is out of scope for a CWE-209 path-disclosure fix. Only the traceback path-redaction change remains.
|
Much simpler change now. Also opened #22664 to track the superuser gate. |
Closes: #22654
Summary
ConfigTemplate.format_render_error()now strips the absolute install-path prefix from allFile "..."lines in the Jinja2 traceback before returning it, so internal filesystem layout is not disclosed to users (CWE-209).Root cause
ConfigTemplate.format_render_error()returnedtraceback.format_exception(exc)verbatim whendebug=True. The output includesFile "/abs/install/path/..."entries for every Python frame in the traceback, revealing the absolute filesystem layout of the NetBox installation to whoever can trigger a render error (CWE-209).Fix
Path redaction — after calling
traceback.format_exception(), applyre.subwith a pattern anchored tore.escape(install_root)(computed asos.path.dirname(settings.BASE_DIR) + os.sep) to replace the absolute prefix with an empty string. The result is a traceback with paths relative to the repo root, which is safe to show. When the venv lives outside the repo, its root is stripped separately as well.Tests
Added
test_format_render_error_debug_redacts_install_pathandtest_format_render_error_non_debug_returns_concise_messagetoConfigTemplateDebugTestCaseinextras/tests/test_models.py. Existingtest_render_jinja2_*andConfigTemplateTestCasetests continue to pass.