mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-02 00:17:49 +01:00
fix(plugins): correct Rust codegen serde attributes and harden endpoint responses
Fix two issues from PR #5045 review. The Rust code generator was producing incorrect skip_serializing_if attributes: map types incorrectly used Option::is_none instead of HashMap::is_empty, and the bare int type for HTTPHandleResponse.Status fell through to the default Option::is_none case. The map fix is in skipSerializingFunc; the int issue is fixed at the source by changing Status from int to int32 (HTTP status codes always fit in int32, and this avoids platform-dependent int sizing on i386 vs amd64). Additionally, plugin HTTP responses now include forced security headers (X-Content-Type-Options: nosniff and a restrictive Content-Security-Policy with sandbox) to prevent XSS from compromised plugins serving HTML+JS on the same origin as Navidrome.
This commit is contained in:
parent
5c52bbb130
commit
9a004fd043
8 changed files with 57 additions and 11 deletions
|
|
@ -17,6 +17,7 @@ type HTTPHandleRequest struct {
|
|||
Method string `json:"method"`
|
||||
// Path is the request path relative to the plugin's base URL.
|
||||
// For example, if the full URL is /ext/my-plugin/webhook, Path is "/webhook".
|
||||
// Both /ext/my-plugin and /ext/my-plugin/ are normalized to Path = "".
|
||||
Path string `json:"path"`
|
||||
// Query is the raw query string without the leading '?'.
|
||||
Query string `json:"query,omitempty"`
|
||||
|
|
@ -31,7 +32,7 @@ type HTTPHandleRequest struct {
|
|||
// HTTPHandleResponse is the response returned by the plugin's HandleRequest function.
|
||||
type HTTPHandleResponse struct {
|
||||
// Status is the HTTP status code. Defaults to 200 if zero or not set.
|
||||
Status int `json:"status,omitempty"`
|
||||
Status int32 `json:"status,omitempty"`
|
||||
// Headers contains the HTTP response headers to set.
|
||||
Headers map[string][]string `json:"headers,omitempty"`
|
||||
// Body is the response body content.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ type HTTPHandleRequest struct {
|
|||
Method string `json:"method"`
|
||||
// Path is the request path relative to the plugin's base URL.
|
||||
// For example, if the full URL is /ext/my-plugin/webhook, Path is "/webhook".
|
||||
// Both /ext/my-plugin and /ext/my-plugin/ are normalized to Path = "".
|
||||
Path string `json:"path"`
|
||||
// Query is the raw query string without the leading '?'.
|
||||
Query string `json:"query,omitempty"`
|
||||
|
|
@ -28,7 +29,7 @@ type HTTPHandleRequest struct {
|
|||
// HTTPHandleResponse is the response returned by the plugin's HandleRequest function.
|
||||
type HTTPHandleResponse struct {
|
||||
// Status is the HTTP status code. Defaults to 200 if zero or not set.
|
||||
Status int `json:"status,omitempty"`
|
||||
Status int32 `json:"status,omitempty"`
|
||||
// Headers contains the HTTP response headers to set.
|
||||
Headers map[string][]string `json:"headers,omitempty"`
|
||||
// Body is the response body content.
|
||||
|
|
|
|||
|
|
@ -28,13 +28,14 @@ pub struct HTTPHandleRequest {
|
|||
pub method: String,
|
||||
/// Path is the request path relative to the plugin's base URL.
|
||||
/// For example, if the full URL is /ext/my-plugin/webhook, Path is "/webhook".
|
||||
/// Both /ext/my-plugin and /ext/my-plugin/ are normalized to Path = "".
|
||||
#[serde(default)]
|
||||
pub path: String,
|
||||
/// Query is the raw query string without the leading '?'.
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
pub query: String,
|
||||
/// Headers contains the HTTP request headers.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub headers: std::collections::HashMap<String, Vec<String>>,
|
||||
/// Body is the request body content.
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
|
|
@ -48,10 +49,10 @@ pub struct HTTPHandleRequest {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HTTPHandleResponse {
|
||||
/// Status is the HTTP status code. Defaults to 200 if zero or not set.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default, skip_serializing_if = "is_zero_i32")]
|
||||
pub status: i32,
|
||||
/// Headers contains the HTTP response headers to set.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub headers: std::collections::HashMap<String, Vec<String>>,
|
||||
/// Body is the response body content.
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue