security(gen1): bound public Hypergrid bulk asset enumeration without blocking commerce (#330)
* security(gen1): bound public Hypergrid asset-existence XML and batch size * security(gen1): limit only public HG asset enumeration; keep normal GET and private services * config(gen1): bound public HG bulk existence requests, keep trade enabled * config(gen1): bound public HG bulk existence requests, keep trade enabled * config(gen1): bound public HG bulk existence requests, keep trade enabled * config(gen1): bound public HG bulk existence requests, keep trade enabled * config(gen1): bound public HG bulk existence requests, keep trade enabled * config(gen1): bound public HG bulk existence requests, keep trade enabled * test(gen1): assert bounded public HG existence requests and open commerce * docs(gen1): document HG batch guard and legitimate commerce acceptance * test(gen1): account for nested HG-only guard while keeping private constructor check
This commit is contained in:
1 parent
09d329eb56
commit
46b45135b4
10 files changed
+117
-6
No files matched your search
@@ -115,13 +115,25 @@ namespace OpenSim.Server.Handlers.Asset
|
||||
// Hypergrid reads. A blocked HG service must never expose raw
|
||||
// asset, metadata or UUID-existence HTTP endpoints on the public port.
|
||||
// The private [AssetService] listener keeps its ordinary read routes.
|
||||
bool hgExportLocked = String.Equals(m_ConfigName, "HGAssetService",
|
||||
StringComparison.OrdinalIgnoreCase) &&
|
||||
bool isHGAssetService = String.Equals(m_ConfigName, "HGAssetService",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
bool hgExportLocked = isHGAssetService &&
|
||||
serverConfig.GetBoolean("DisallowAllExport", false);
|
||||
if (!hgExportLocked)
|
||||
{
|
||||
server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth, redirectURL));
|
||||
server.AddStreamHandler(new AssetsExistHandler(m_AssetService));
|
||||
if (isHGAssetService)
|
||||
{
|
||||
// Public HG traffic: cap high-volume UUID enumeration and
|
||||
// XML request size, not legal per-asset GETs or commerce.
|
||||
// A single normal large object can refer to many assets,
|
||||
// so defaults deliberately allow substantial HG batches.
|
||||
int maxIds = Math.Clamp(serverConfig.GetInt("MaxHGAssetExistIds", 16384), 256, 65536);
|
||||
int maxXml = Math.Clamp(serverConfig.GetInt("MaxHGAssetExistXmlChars", 4194304), 65536, 16777216);
|
||||
server.AddStreamHandler(new AssetsExistHandler(m_AssetService, maxIds, maxXml));
|
||||
}
|
||||
else
|
||||
server.AddStreamHandler(new AssetsExistHandler(m_AssetService));
|
||||
}
|
||||
server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth));
|
||||
|
||||
|
||||
@@ -49,6 +49,17 @@ namespace OpenSim.Server.Handlers.Asset
|
||||
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private IAssetService m_AssetService;
|
||||
// Zero preserves the legacy private AssetService behavior. Limits are
|
||||
// set only by the public HG connector to bound asset-ID enumeration.
|
||||
private int m_MaxIds;
|
||||
private long m_MaxXmlCharacters;
|
||||
|
||||
public AssetsExistHandler(IAssetService service, int maxIds, long maxXmlCharacters) :
|
||||
this(service)
|
||||
{
|
||||
m_MaxIds = Math.Max(0, maxIds);
|
||||
m_MaxXmlCharacters = Math.Max(0, maxXmlCharacters);
|
||||
}
|
||||
|
||||
public AssetsExistHandler(IAssetService service) :
|
||||
base("POST", "/get_assets_exist")
|
||||
@@ -70,7 +81,17 @@ namespace OpenSim.Server.Handlers.Asset
|
||||
try
|
||||
{
|
||||
xs = new XmlSerializer(typeof(string[]));
|
||||
ids = (string[])xs.Deserialize(request);
|
||||
// Defend the public HG existence endpoint against unbounded
|
||||
// XML and entity payloads, without affecting authorized GET
|
||||
// downloads or ordinary foreign-grid inventory transfers.
|
||||
using (XmlReader xmlReader = XmlReader.Create(request, new XmlReaderSettings
|
||||
{
|
||||
DtdProcessing = DtdProcessing.Prohibit,
|
||||
XmlResolver = null,
|
||||
MaxCharactersInDocument = m_MaxXmlCharacters,
|
||||
CloseInput = false
|
||||
}))
|
||||
ids = (string[])xs.Deserialize(xmlReader);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -78,6 +99,18 @@ namespace OpenSim.Server.Handlers.Asset
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ids == null)
|
||||
{
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (m_MaxIds > 0 && ids.Length > m_MaxIds)
|
||||
{
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.RequestEntityTooLarge;
|
||||
return null;
|
||||
}
|
||||
|
||||
bool[] exist = m_AssetService.AssetsExist(ids);
|
||||
|
||||
xs = new XmlSerializer(typeof(bool[]));
|
||||
|
||||
@@ -1022,6 +1022,10 @@
|
||||
; Generation 1: allow normal Hypergrid commerce and delivery of purchased assets.
|
||||
; Emergency opt-in lockdown: true denies ALL public HG reads (including sales).
|
||||
DisallowAllExport = false
|
||||
; Only applies to public HG POST /get_assets_exist (not normal asset GETs).
|
||||
; Large legal transfers remain supported; limits mitigate bulk enumeration.
|
||||
MaxHGAssetExistIds = 16384
|
||||
MaxHGAssetExistXmlChars = 4194304
|
||||
;; Use the second option if you have FSAsset service enabled
|
||||
LocalServiceModule = "OpenSim.Services.HypergridService.dll:HGAssetService"
|
||||
;LocalServiceModule = "OpenSim.Services.HypergridService.dll:HGFSAssetService"
|
||||
|
||||
@@ -937,6 +937,10 @@
|
||||
; Generation 1: allow normal Hypergrid commerce and delivery of purchased assets.
|
||||
; Emergency opt-in lockdown: true denies ALL public HG reads (including sales).
|
||||
DisallowAllExport = false
|
||||
; Only applies to public HG POST /get_assets_exist (not normal asset GETs).
|
||||
; Large legal transfers remain supported; limits mitigate bulk enumeration.
|
||||
MaxHGAssetExistIds = 16384
|
||||
MaxHGAssetExistXmlChars = 4194304
|
||||
;; Use the second option if you have FSAsset service enabled
|
||||
; FSAssets-aware Hypergrid asset service.
|
||||
;LocalServiceModule = "OpenSim.Services.HypergridService.dll:HGAssetService"
|
||||
|
||||
@@ -986,6 +986,10 @@
|
||||
; Generation 1: allow normal Hypergrid commerce and delivery of purchased assets.
|
||||
; Emergency opt-in lockdown: true denies ALL public HG reads (including sales).
|
||||
DisallowAllExport = false
|
||||
; Only applies to public HG POST /get_assets_exist (not normal asset GETs).
|
||||
; Large legal transfers remain supported; limits mitigate bulk enumeration.
|
||||
MaxHGAssetExistIds = 16384
|
||||
MaxHGAssetExistXmlChars = 4194304
|
||||
;; Use the second option if you have FSAsset service enabled
|
||||
LocalServiceModule = "OpenSim.Services.HypergridService.dll:HGAssetService"
|
||||
;LocalServiceModule = "OpenSim.Services.HypergridService.dll:HGFSAssetService"
|
||||
|
||||
@@ -225,6 +225,10 @@
|
||||
; Generation 1: allow normal Hypergrid commerce and delivery of purchased assets.
|
||||
; Emergency opt-in lockdown: true denies ALL public HG reads (including sales).
|
||||
DisallowAllExport = false
|
||||
; Only applies to public HG POST /get_assets_exist (not normal asset GETs).
|
||||
; Large legal transfers remain supported; limits mitigate bulk enumeration.
|
||||
MaxHGAssetExistIds = 16384
|
||||
MaxHGAssetExistXmlChars = 4194304
|
||||
;
|
||||
; === HG ONLY ===
|
||||
;; The asset types that this grid can export to / import from other grids.
|
||||
|
||||
@@ -203,6 +203,10 @@
|
||||
; Generation 1: allow normal Hypergrid commerce and delivery of purchased assets.
|
||||
; Emergency opt-in lockdown: true denies ALL public HG reads (including sales).
|
||||
DisallowAllExport = false
|
||||
; Only applies to public HG POST /get_assets_exist (not normal asset GETs).
|
||||
; Large legal transfers remain supported; limits mitigate bulk enumeration.
|
||||
MaxHGAssetExistIds = 16384
|
||||
MaxHGAssetExistXmlChars = 4194304
|
||||
;
|
||||
; === HG ONLY ===
|
||||
;; The asset types that this grid can export to / import from other grids.
|
||||
|
||||
@@ -313,6 +313,10 @@
|
||||
; Generation 1: allow normal Hypergrid commerce and delivery of purchased assets.
|
||||
; Emergency opt-in lockdown: true denies ALL public HG reads (including sales).
|
||||
DisallowAllExport = false
|
||||
; Only applies to public HG POST /get_assets_exist (not normal asset GETs).
|
||||
; Large legal transfers remain supported; limits mitigate bulk enumeration.
|
||||
MaxHGAssetExistIds = 16384
|
||||
MaxHGAssetExistXmlChars = 4194304
|
||||
;; The asset types that this grid can export to / import from other grids.
|
||||
;; Comma separated.
|
||||
;; Valid values are all the asset types in OpenMetaverse.AssetType, namely:
|
||||
|
||||
@@ -53,3 +53,26 @@ The intended protection roadmap is therefore:
|
||||
6. Optionally test the emergency lockdown on an isolated disposable stage; restore the **open** default afterwards.
|
||||
|
||||
**No production rollout is performed by this code change.** Stable `v0.9.3.13` remains unchanged.
|
||||
|
||||
## Public Hypergrid batch-enumeration guard (Generation 1, next security block)
|
||||
|
||||
The public `POST /get_assets_exist` endpoint historically deserialized arbitrarily large XML arrays and could enumerate unlimited asset IDs in one request. The connector now enforces limits **only for the public [HGAssetService]**. This reduces unbounded batch enumeration and XML resource exhaustion while leaving lawful per-asset GETs and authorized outgoing inventory/assets unchanged.
|
||||
|
||||
```ini
|
||||
[HGAssetService]
|
||||
DisallowAllExport = false
|
||||
MaxHGAssetExistIds = 16384
|
||||
MaxHGAssetExistXmlChars = 4194304
|
||||
```
|
||||
|
||||
Values can be tuned to real grids' legitimate batch sizes. The server clamps the first value to 256–65536 IDs and the second to 65536–16777216 XML characters. The defaults intentionally accommodate large, legitimate objects; above-limit batch IDs receive HTTP 413, and oversized/malformed XML receives HTTP 400. XML DTDs and external entities are prohibited. On a private [AssetService] the legacy batch-limit behavior is unchanged, but XML DTDs are still prohibited. The independent inbound asset POST stays available and is not affected.
|
||||
|
||||
This does **not** distinguish Darkstorm from Firestorm, does **not** block a malicious viewer saving rendered asset data, and does not prevent an attacker from splitting requests into smaller batches. A hard cap is an abuse-resistance layer, not copy protection or user authorization.
|
||||
|
||||
### Acceptance and negative tests
|
||||
|
||||
- Public HG: exactly 16384 IDs parses and passes to the service (valid IDs), 16385 returns 413 before any lookup.
|
||||
- Public HG: a small valid `string[]` XML request responds as before; malformed XML, DTD, or an XML body over 4194304 characters fails without a lookup.
|
||||
- Private [AssetService]: large internal batch operations remain unaffected by the public limit.
|
||||
- Actual HG visitor: purchase, suitcase transfer, home-grid rez, wearables and textured mesh attachments function; import and public HG GET paths remain available.
|
||||
- Monitor and adjust the HG thresholds only if real production telemetry reveals oversized legitimate batches. Do not disable trade to respond to copybot activity.
|
||||
@@ -33,7 +33,24 @@ assert 'String.Equals(m_ConfigName, "HGAssetService"' in connector
|
||||
assert 'serverConfig.GetBoolean("DisallowAllExport", false)' in connector
|
||||
assert "if (!hgExportLocked)" in connector
|
||||
assert "new AssetServerGetHandler(m_AssetService, auth, redirectURL)" in connector.split("if (!hgExportLocked)", 1)[1].split("}", 1)[0]
|
||||
assert "new AssetsExistHandler(m_AssetService)" in connector.split("if (!hgExportLocked)", 1)[1].split("}", 1)[0]
|
||||
assert "new AssetsExistHandler(m_AssetService)" in connector # private connector remains unbounded
|
||||
assert 'bool isHGAssetService = String.Equals(m_ConfigName, "HGAssetService"' in connector
|
||||
assert 'serverConfig.GetInt("MaxHGAssetExistIds", 16384)' in connector
|
||||
assert 'serverConfig.GetInt("MaxHGAssetExistXmlChars", 4194304)' in connector
|
||||
assert 'new AssetsExistHandler(m_AssetService, maxIds, maxXml)' in connector
|
||||
|
||||
exist = read("OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs")
|
||||
for marker in (
|
||||
'public AssetsExistHandler(IAssetService service, int maxIds, long maxXmlCharacters)',
|
||||
'DtdProcessing = DtdProcessing.Prohibit',
|
||||
'XmlResolver = null',
|
||||
'MaxCharactersInDocument = m_MaxXmlCharacters',
|
||||
'if (m_MaxIds > 0 && ids.Length > m_MaxIds)',
|
||||
'HttpStatusCode.RequestEntityTooLarge',
|
||||
'm_AssetService.AssetsExist(ids)',
|
||||
):
|
||||
assert marker in exist, marker
|
||||
assert exist.index('if (m_MaxIds > 0 && ids.Length > m_MaxIds)') < exist.index('m_AssetService.AssetsExist(ids)')
|
||||
assert "server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth));" in connector
|
||||
|
||||
for path, base_get, base_meta, exists in [
|
||||
@@ -63,6 +80,8 @@ for name in (
|
||||
):
|
||||
hg = section(name, "HGAssetService")
|
||||
assert "DisallowAllExport = false" in hg, name
|
||||
assert "MaxHGAssetExistIds = 16384" in hg, name
|
||||
assert "MaxHGAssetExistXmlChars = 4194304" in hg, name
|
||||
assert not any(line.strip().startswith("DisallowImport =")
|
||||
for line in hg.splitlines()), name
|
||||
|
||||
@@ -76,4 +95,4 @@ for name in (
|
||||
|
||||
notes = read("doc/NexVerse/GEN1_ASSET_EGRESS_LOCKDOWN.md")
|
||||
assert "no secure server-side switch" in notes and "Open Hypergrid commerce" in notes
|
||||
print("Generation 1 HG: commerce defaults open; emergency lockdown code and policy verified")
|
||||
print("Generation 1 HG: commerce open, emergency lockdown opt-in, HG bulk-existence guard verified")
|
||||
Reference in new issue
Block a user