mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-03 20:44:36 +00:00
Compare commits
2 Commits
v4.9.7
...
fix/plugin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa4b5d6732 | ||
|
|
b251fc4b89 |
@@ -39,6 +39,16 @@ def _normalize_plugin_asset_path(filepath: str) -> str | None:
|
|||||||
return f'assets/{normalized}'
|
return f'assets/{normalized}'
|
||||||
|
|
||||||
|
|
||||||
|
def _get_request_origin() -> str:
|
||||||
|
"""Return the public request origin, respecting reverse-proxy headers."""
|
||||||
|
forwarded_proto = quart.request.headers.get('X-Forwarded-Proto', '').split(',')[0].strip()
|
||||||
|
forwarded_host = quart.request.headers.get('X-Forwarded-Host', '').split(',')[0].strip()
|
||||||
|
|
||||||
|
scheme = forwarded_proto or quart.request.scheme
|
||||||
|
host = forwarded_host or quart.request.host
|
||||||
|
return f'{scheme}://{host}'
|
||||||
|
|
||||||
|
|
||||||
@group.group_class('plugins', '/api/v1/plugins')
|
@group.group_class('plugins', '/api/v1/plugins')
|
||||||
class PluginsRouterGroup(group.RouterGroup):
|
class PluginsRouterGroup(group.RouterGroup):
|
||||||
async def _check_extensions_limit(self) -> str | None:
|
async def _check_extensions_limit(self) -> str | None:
|
||||||
@@ -189,7 +199,7 @@ class PluginsRouterGroup(group.RouterGroup):
|
|||||||
# CSP for HTML pages served to sandboxed iframes (opaque origin).
|
# CSP for HTML pages served to sandboxed iframes (opaque origin).
|
||||||
# 'self' doesn't work in sandboxed iframes — use actual server origin.
|
# 'self' doesn't work in sandboxed iframes — use actual server origin.
|
||||||
if mime_type and mime_type.startswith('text/html'):
|
if mime_type and mime_type.startswith('text/html'):
|
||||||
origin = f'{quart.request.scheme}://{quart.request.host}'
|
origin = _get_request_origin()
|
||||||
resp.headers['Content-Security-Policy'] = (
|
resp.headers['Content-Security-Policy'] = (
|
||||||
f'default-src {origin}; '
|
f'default-src {origin}; '
|
||||||
f"script-src {origin} 'unsafe-inline'; "
|
f"script-src {origin} 'unsafe-inline'; "
|
||||||
|
|||||||
@@ -633,11 +633,12 @@ class PluginRuntimeConnector:
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError: If plugin_id is not in the expected 'author/name' format.
|
ValueError: If plugin_id is not in the expected 'author/name' format.
|
||||||
"""
|
"""
|
||||||
if '/' not in plugin_id:
|
segments = plugin_id.split('/')
|
||||||
|
if len(segments) != 2 or not all(segments):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid plugin_id format: '{plugin_id}'. Expected 'author/name' format (e.g. 'langbot/rag-engine')."
|
f"Invalid plugin_id format: '{plugin_id}'. Expected 'author/name' format (e.g. 'langbot/rag-engine')."
|
||||||
)
|
)
|
||||||
return plugin_id.split('/', 1)
|
return segments[0], segments[1]
|
||||||
|
|
||||||
async def call_rag_ingest(self, plugin_id: str, context_data: dict[str, Any]) -> dict[str, Any]:
|
async def call_rag_ingest(self, plugin_id: str, context_data: dict[str, Any]) -> dict[str, Any]:
|
||||||
"""Call plugin to ingest document.
|
"""Call plugin to ingest document.
|
||||||
|
|||||||
25
tests/unit_tests/plugin/test_plugin_id_parsing.py
Normal file
25
tests/unit_tests/plugin/test_plugin_id_parsing.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
"""Test plugin ID parsing validation."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from src.langbot.pkg.plugin.connector import PluginRuntimeConnector
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_plugin_id_accepts_author_name():
|
||||||
|
assert PluginRuntimeConnector._parse_plugin_id('langbot/rag-engine') == ('langbot', 'rag-engine')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'plugin_id',
|
||||||
|
[
|
||||||
|
'',
|
||||||
|
'author',
|
||||||
|
'author/',
|
||||||
|
'/name',
|
||||||
|
'author/name/extra',
|
||||||
|
'/',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_parse_plugin_id_rejects_malformed_ids(plugin_id):
|
||||||
|
with pytest.raises(ValueError, match='Expected'):
|
||||||
|
PluginRuntimeConnector._parse_plugin_id(plugin_id)
|
||||||
@@ -590,6 +590,9 @@ export class BackendClient extends BaseHttpClient {
|
|||||||
name: string,
|
name: string,
|
||||||
filepath: string,
|
filepath: string,
|
||||||
): string {
|
): string {
|
||||||
|
if (this.instance.defaults.baseURL === '/') {
|
||||||
|
return `${window.location.origin}/api/v1/plugins/${author}/${name}/assets/${filepath}`;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
this.instance.defaults.baseURL +
|
this.instance.defaults.baseURL +
|
||||||
`/api/v1/plugins/${author}/${name}/assets/${filepath}`
|
`/api/v1/plugins/${author}/${name}/assets/${filepath}`
|
||||||
|
|||||||
Reference in New Issue
Block a user