Script run responses include storage backend error text

Open
#88 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
security

Research direction

Start by reading validation.py around build_error_sanitizer and storage/store.py around _stream_verified, then trace how script_class_context passes load errors to the REST and UI views. Check how the sanitizer handles backend-specific error details while preserving useful administrator logging. Done when script run responses omit storage backend details and the full error remains available in server logs; consider the upload path covered by #77.

Written by the indexing model from the issue text.

Description

app: scripts severity: low status: backlog type: bug
Plugin Version

v0.0.1 (also present on main)

NetBox Version

v4.7.4

Python Version

3.12

Steps to Reproduce
  1. Use the default filesystem storage backend for script source.
  2. Activate a revision for an upload project so it has a runnable Script.
  3. Make that revision's stored files unreadable by the NetBox process, and clear the local runtime cache so the run has to read from storage.
  4. Run the Script through the REST API (POST /api/plugins/scripts/scripts/<id>/run/), or from its run view in the UI.
Expected Behavior

The response says the Script could not be loaded, without storage backend details. The full error goes to the server log for the administrator.

Observed Behavior

Found by reading the code on main, not by running these steps. The example message below shows the shape the code produces, not captured output.

The load failure is shown to the user by api/views.py:351-358 (REST) and views/scripts.py:198 (UI). It comes from script_class_context, which passes the error through build_error_sanitizer (validation.py:239-261). The sanitizer replaces the storage key, digest, local cache directory and runtime root, but not the storage backend's own root path or other backend text. Reading a stored file wraps the backend exception text (storage/store.py, _stream_verified), so a filesystem read failure still shows something like Permission denied: '/opt/netbox/netbox/media/<scripts root>/<storage>/<digest>/script.py'. Other backends would include their own error text, such as an S3 endpoint URL.

The upload path has the same root cause and is covered by #77. CodeQL reports this one as py/stack-trace-exposure (alert 3).

Dominant language
Python
Stars
8
Forks
0
Avg merge
9h 56m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from netbox-community/netbox-scripts

All issues in netbox-community/netbox-scripts

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.