T09 · Insecure Skill Coding Practices
- Location
references/component-specs.md:548- Finding
Untrusted JSON Input Can Control Tensor and Neural-Network Allocations
- Content
View full analysis
Vulnerability Details
File Location:
references/component-specs.md:548-656
Vulnerability Type: Unbounded resource allocation from unvalidated input
Risk Level: MediumVulnerable Code
python def load_graph(path: str) -> Tuple[Dict[int, EntityState], List[CausalEdge]]: """Load a causal graph from .graph.json.""" with open(path) as f: data = json.load(f) entities = {} for e_data in data['entities']: entity = EntityState( id=e_data['id'], name=e_data['name'], type=e_data['type'], domain=e_data['domain'], q=torch.tensor(e_data['position']['values'], dtype=torch.float64), p=torch.tensor(e_data['momentum']['values'], dtype=torch.float64), attributes=_convert_attrs(e_data['attributes']), belief_mean=torch.tensor(e_data['belief']['mean'], dtype=torch.float64), belief_cov=torch.tensor( e_data['belief']['covariance'], dtype=torch.float64, ), ) entities[entity.id] = entity edges = [] for e_data in data['edges']: mechanism = _create_mechanism(e_data) edge = CausalEdge( source_id=e_data['source_id'], target_id=e_data['target_id'], mechanism=mechanism, mechanism_type=e_data['mechanism_type'], strength=e_data['strength'], delay=e_data['delay'], confidence=e_data['confidence'], ) edges.append(edge) return entities, edgespython elif m_type == 'pinn_learned': pinn_cfg = params.get('pinn_params', {}) return PINNMechanism( state_dim=pinn_cfg.get('input_dim', 6), hidden_dims=pinn_cfg.get('network_arch', [64, 64, 32]), ) else: from src.mechanisms.causal_mechanism import CausalMechanismFunction return CausalMechanismFunction( causal_type=m_type, state_dim=params.get(' ...[truncated 2569 chars]- Remediation
View remediation
Remediation Suggestions
- Enforce a maximum input-file size before calling
json.load(). - Validate every document against a strict JSON Schema before constructing tensors or models.
- Set explicit upper bounds for:
- Entity and edge counts.
- State-vector dimensions.
- Covariance dimensions.
- Number of neural-network layers.
- Width of each layer.
- Total estimated model parameter count.
- Calculate the expected allocation size before constructing tensors or modules and reject inputs exceeding a configured memory budget.
- Reject negative, non-integer, zero, excessively large, or otherwise invalid architecture dimensions.
- Require all physical and statistical values to be finite; reject
NaNand infinity. - Verify that belief covariance matrices are square, symmetric, dimensionally consistent, and positive definite.
- Validate that entity identifiers are unique and that every edge references existing entities.
- Constrain mechanism types and function forms to an explicit allowlist.
- Apply process-level memory, CPU, and execution-time limits when processing externally supplied datasets.
- Return controlled validation errors rather than allowing raw allocation or linear-algebra exceptions to terminate the application.
- Enforce a maximum input-file size before calling
