Commit 23d5feb
authored
Fix Viewer serving non-HTML content in web mode via positron proxy (#8793)
Addresses #8785
### Before this fix, when running in web mode, the HtmlProxyServer was:
- Reading ALL files (HTML, CSS, JS, images, etc.) as UTF-8 text
- Using `res.send(content)` for all files, which doesn't set proper
`Content-Type` headers
- This caused CSS files to be served as `text/html` instead of
`text/css`, JS files as `text/html` instead of `application/javascript`,
etc.
### Now the code:
- For HTML files: Continues to read them as text and inject HTML
resources if needed (preserving the existing functionality)
- For non-HTML files: Uses `res.sendFile()` with the `root` option,
which automatically sets the correct `Content-Type` headers based on
file extensions
### Why res.sendFile() with root option:
- Built-in MIME type detection that properly maps file extensions to
`Content-Type` headers
- Built-in path traversal protection via the `root` option
- Only HTML files need special processing (resource injection), so other
files can use the standard secure file serving
- Simpler and more secure than manual path validation or dynamic
`express.static()` calls
- This preserves the existing HTML processing while fixing the
Content-Type issue for all other file types.
This should resolve the issue where the proxy was sending back the wrong
`Content-Type` header for non-HTML content like .js or .css files, which
is important if the client is strictly enforcing the MIME type (such as
when `nosniff` was enforced, which is the case in Workbench Positron Pro
sessions).
## New Features
N/A
## Bug Fixes
- Fixed an issue with non-HTML content being served through Positron
Proxy for the Viewer Pane in web mode.
## QA Notes
Need to verify interactive plots in the Viewer function in Positron Pro
in Workbench
@:web @:critical1 parent a20ee3f commit 23d5feb
1 file changed
+12
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
104 | 111 | | |
105 | | - | |
106 | 112 | | |
107 | 113 | | |
108 | 114 | | |
| |||
0 commit comments