shellui-django 0.4.0__tar.gz → 0.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {shellui_django-0.4.0 → shellui_django-0.5.1}/CHANGELOG.md +26 -0
  2. {shellui_django-0.4.0 → shellui_django-0.5.1}/PKG-INFO +1 -1
  3. {shellui_django-0.4.0 → shellui_django-0.5.1}/pyproject.toml +1 -1
  4. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/__init__.py +1 -1
  5. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/__init__.py +2 -0
  6. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/delegation.py +7 -3
  7. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/identity_jwks.py +41 -2
  8. shellui_django-0.5.1/src/shellui_django/mcp/internal.py +673 -0
  9. shellui_django-0.5.1/src/shellui_django/mcp/openapi_tools.py +326 -0
  10. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/resources.py +18 -3
  11. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/rs256_helpers.py +12 -0
  12. shellui_django-0.5.1/src/shellui_django/mcp/tests/test_approval_authority.py +261 -0
  13. shellui_django-0.5.1/src/shellui_django/mcp/tests/test_identity_jwks_decode.py +104 -0
  14. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_internal_assertions.py +18 -0
  15. shellui_django-0.5.1/src/shellui_django/mcp/tests/test_internal_revocation.py +517 -0
  16. shellui_django-0.5.1/src/shellui_django/mcp/tests/test_openapi_tools.py +207 -0
  17. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_package.py +7 -0
  18. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_resources.py +13 -0
  19. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/write_gate.py +3 -1
  20. shellui_django-0.4.0/src/shellui_django/mcp/internal.py +0 -387
  21. shellui_django-0.4.0/src/shellui_django/mcp/openapi_tools.py +0 -120
  22. shellui_django-0.4.0/src/shellui_django/mcp/tests/test_internal_revocation.py +0 -109
  23. shellui_django-0.4.0/src/shellui_django/mcp/tests/test_openapi_tools.py +0 -25
  24. {shellui_django-0.4.0 → shellui_django-0.5.1}/.gitignore +0 -0
  25. {shellui_django-0.4.0 → shellui_django-0.5.1}/LICENSE +0 -0
  26. {shellui_django-0.4.0 → shellui_django-0.5.1}/README.md +0 -0
  27. {shellui_django-0.4.0 → shellui_django-0.5.1}/SECURITY.md +0 -0
  28. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/decorators.py +0 -0
  29. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/gateway.py +0 -0
  30. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/masking.py +0 -0
  31. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/openapi_mcp.py +0 -0
  32. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/rate_limit.py +0 -0
  33. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/routing.py +0 -0
  34. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/server.py +0 -0
  35. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/__init__.py +0 -0
  36. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/mcp_routing_urlconf.py +0 -0
  37. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_delegation.py +0 -0
  38. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_gateway.py +0 -0
  39. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_masking.py +0 -0
  40. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_routing.py +0 -0
  41. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_server_routing.py +0 -0
  42. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/mcp/tests/test_write_gate_mcp.py +0 -0
  43. {shellui_django-0.4.0 → shellui_django-0.5.1}/src/shellui_django/testing/__init__.py +0 -0
@@ -23,6 +23,32 @@ Breaking changes bump the major version (minor while below 1.0.0), so services c
23
23
  See for sample https://raw.githubusercontent.com/favoloso/conventional-changelog-emoji/master/CHANGELOG.md
24
24
  -->
25
25
 
26
+ ## [0.5.1] - 2026-11-09
27
+
28
+ ### 🐛 Bug Fixes
29
+
30
+ - MCP resource indicators: allow plain `http` for private and CGNAT (RFC 6598 `100.64.0.0/10`, e.g. Tailscale) IP literals in addition to loopback. Public hostnames over `http` remain rejected.
31
+ - `tools_from_schema`: resolve OpenAPI `$ref` request bodies and emit typed `body` / `query` properties. Previously `$ref`-only bodies (common with drf-spectacular) produced an empty `body` object, so MCP clients could not submit fields such as template draft `subject` / `document`. Untyped JSONField fragments become free-form objects (`additionalProperties: true`).
32
+ - `tools_from_schema`: field schemas also resolve nested `$ref`, `allOf`, and `oneOf`/`anyOf` wrappers, so drf-spectacular choice fields stay typed strings with their `enum` values, nested serializers stay typed objects, and nullable fields accept `null`.
33
+
34
+ ### 📚 Documentation
35
+
36
+ - Document private/CGNAT `http` resource URLs and `$ref` body expansion for MCP tools.
37
+
38
+ ## [0.5.0] - 2026-11-06
39
+
40
+ ### 🛠 Improvements
41
+
42
+ - MCP internal assertions: optional regional authority fields on `build_mcp_approval_assertion` (`grant_version`, `global_company_id`, `company_binding_version`) and optional revocation policy metadata on `build_mcp_revocation_list_response_assertion` (`revocation_policy_version`, `max_active_grant_version`); strict non-negative integers, delegated global pair rules (`is not None` only), body and JWT parity for top-level policy fields (legacy digit strings on the HTTP envelope), per-agent binding validation with `mcp_authority_snapshot_fingerprint` and `mcp_authority_snapshot_rejected` on trusted rows, delegated grant cap checks against signed `max_active_grant_version` without blocking personal rows, `jti` and lifetime invariants (`exp` after `iat`, 600 s cap) on Identity-signed revocation lists, and positive `cache_seconds` bounded by the same cap.
43
+ - Revocation list verification: strict `iat` / `exp` types after decode (reject bool and float; digit strings coerced), clock window aligned with `IDENTITY_RS256_LEEWAY_SECONDS` (5 s) on `decode_identity_rs256_jwt`.
44
+ - `decode_identity_rs256_jwt` always requires `exp`, `iat`, `sub`, `scope`, and `jti`; `require_claims` adds further required names (union). Timestamps are normalized to integers after verify.
45
+ - `verify_rs256_mcp_assertion` lifetime checks use the same strict timestamp parsing as revocation (no `int()` on raw claims).
46
+ - Destructive MCP tools always require approval in `full` mode; `mcp_destructive` does not skip the gate.
47
+
48
+ ### 📚 Documentation
49
+
50
+ - `docs/mcp.md`: regional authority, revocation policy proof, per-agent binding snapshots, numeric `0` vs omitted or `None`, `decode_identity_rs256_jwt` requirements, and destructive approval rules.
51
+
26
52
  ## [0.4.0] - 2026-11-04
27
53
 
28
54
  ### 🔒 Security
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: shellui-django
3
- Version: 0.4.0
3
+ Version: 0.5.1
4
4
  Summary: Shared Django libraries for Shellui services
5
5
  Project-URL: Homepage, https://shellui.com
6
6
  Project-URL: Source, https://github.com/shellui/django-commons
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "shellui-django"
3
- version = "0.4.0"
3
+ version = "0.5.1"
4
4
  description = "Shared Django libraries for Shellui services"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,3 +1,3 @@
1
1
  """Shared Django libraries for Shellui services."""
2
2
 
3
- __version__ = '0.4.0'
3
+ __version__ = '0.5.1'
@@ -14,6 +14,7 @@ from shellui_django.mcp.internal import (
14
14
  APPROVAL_SCOPE,
15
15
  INTERNAL_ASSERTION_MAX_LIFETIME_SECONDS,
16
16
  REVOCATION_CACHE_SECONDS,
17
+ REVOCATION_LIST_MAX_ASSERTION_LIFETIME_SECONDS,
17
18
  REVOCATION_LIST_SCOPE,
18
19
  build_mcp_approval_assertion,
19
20
  build_mcp_revocation_list_response_assertion,
@@ -35,6 +36,7 @@ __all__ = [
35
36
  'APPROVAL_SCOPE',
36
37
  'INTERNAL_ASSERTION_MAX_LIFETIME_SECONDS',
37
38
  'REVOCATION_CACHE_SECONDS',
39
+ 'REVOCATION_LIST_MAX_ASSERTION_LIFETIME_SECONDS',
38
40
  'REVOCATION_LIST_SCOPE',
39
41
  'build_mcp_approval_assertion',
40
42
  'build_mcp_revocation_list_response_assertion',
@@ -8,6 +8,8 @@ from typing import Any
8
8
 
9
9
  import jwt
10
10
 
11
+ from shellui_django.mcp.identity_jwks import IdentityJwksError, jwt_unix_timestamp_claim_strict
12
+
11
13
  DOWNSTREAM_TOKEN_AUDIENCE = 'shellui-mcp-downstream-token'
12
14
  DOWNSTREAM_TOKEN_SCOPE = 'mcp.downstream_token.mint'
13
15
  DOWNSTREAM_TOKEN_REQUEST_MAX_LIFETIME_SECONDS = 60
@@ -101,10 +103,12 @@ def _resolve_verification_key(token: str, public_jwks_or_pem: dict[str, Any] | s
101
103
 
102
104
  def _assert_lifetime_within_limit(claims: dict[str, Any]) -> None:
103
105
  try:
104
- iat = int(claims['iat'])
105
- exp = int(claims['exp'])
106
- except (KeyError, TypeError, ValueError) as exc:
106
+ iat = jwt_unix_timestamp_claim_strict(claims['iat'], field='iat')
107
+ exp = jwt_unix_timestamp_claim_strict(claims['exp'], field='exp')
108
+ except KeyError as exc:
107
109
  raise DownstreamTokenRequestError('Invalid iat or exp.') from exc
110
+ except IdentityJwksError as exc:
111
+ raise DownstreamTokenRequestError(str(exc)) from exc
108
112
  if exp <= iat:
109
113
  raise DownstreamTokenRequestError('Token lifetime is invalid.')
110
114
  if exp - iat > DOWNSTREAM_TOKEN_REQUEST_MAX_LIFETIME_SECONDS:
@@ -13,6 +13,8 @@ import jwt
13
13
  from jwt.algorithms import RSAAlgorithm
14
14
 
15
15
  _CACHE_TTL_SECONDS = 300
16
+ # Match ``INTERNAL_ASSERTION_LEEWAY_SECONDS`` in ``internal`` for Identity JWT verification.
17
+ IDENTITY_RS256_LEEWAY_SECONDS = 5
16
18
  _cache_lock = threading.Lock()
17
19
  _jwks_cache: dict[str, tuple[float, dict[str, Any]]] = {}
18
20
 
@@ -21,6 +23,27 @@ class IdentityJwksError(Exception):
21
23
  pass
22
24
 
23
25
 
26
+ def jwt_unix_timestamp_claim_strict(value: Any, *, field: str) -> int:
27
+ """``iat`` / ``exp`` after JWT decode: non-negative int, or digit-only string (PyJWT quirk).
28
+
29
+ Rejects bool, float, and non-digit strings so values are not confused via ``int()`` coercion.
30
+ """
31
+ if isinstance(value, bool):
32
+ raise IdentityJwksError(f'{field} must be a Unix timestamp.')
33
+ if isinstance(value, float):
34
+ raise IdentityJwksError(f'{field} must be a Unix timestamp.')
35
+ if isinstance(value, int):
36
+ if value < 0:
37
+ raise IdentityJwksError(f'{field} must be non-negative.')
38
+ return value
39
+ if isinstance(value, str):
40
+ s = value.strip()
41
+ if not s or not s.isdigit():
42
+ raise IdentityJwksError(f'{field} must be a Unix timestamp.')
43
+ return int(s)
44
+ raise IdentityJwksError(f'{field} must be a Unix timestamp.')
45
+
46
+
24
47
  def identity_jwks_url_for_issuer(issuer: str) -> str:
25
48
  base = (issuer or '').strip().rstrip('/')
26
49
  if not base:
@@ -102,20 +125,36 @@ def decode_identity_rs256_jwt(
102
125
  jwks_url: str | None = None,
103
126
  jwks: dict[str, Any] | None = None,
104
127
  timeout: float = 10.0,
128
+ require_claims: tuple[str, ...] = (),
105
129
  ) -> dict[str, Any]:
130
+ """Verify an Identity-issued RS256 JWT against JWKS.
131
+
132
+ Always requires ``exp``, ``iat``, ``sub``, ``scope``, and ``jti``. Names in
133
+ ``require_claims`` add further required claims (union, never a substitute).
134
+ Timestamp claims are normalized to strict non-negative integers after decode.
135
+ """
106
136
  header = jwt.get_unverified_header(token)
107
137
  if header.get('alg') != 'RS256':
108
138
  raise IdentityJwksError('Identity JWT must use RS256.')
109
139
  document = get_jwks_document(jwks_url=jwks_url, jwks=jwks, timeout=timeout)
110
140
  key = resolve_verification_key(token, document)
141
+ mandatory = {'exp', 'iat', 'sub', 'scope', 'jti'}
142
+ merged = sorted(mandatory.union(require_claims))
111
143
  try:
112
- return jwt.decode(
144
+ claims = jwt.decode(
113
145
  token,
114
146
  key=key,
115
147
  algorithms=['RS256'],
116
148
  audience=audience,
117
149
  issuer=issuer,
118
- options={'require': ['exp', 'iat', 'sub', 'scope']},
150
+ leeway=IDENTITY_RS256_LEEWAY_SECONDS,
151
+ options={'require': merged},
119
152
  )
120
153
  except jwt.PyJWTError as exc:
121
154
  raise IdentityJwksError('Invalid Identity JWT.') from exc
155
+ try:
156
+ claims['iat'] = jwt_unix_timestamp_claim_strict(claims['iat'], field='iat')
157
+ claims['exp'] = jwt_unix_timestamp_claim_strict(claims['exp'], field='exp')
158
+ except KeyError as exc:
159
+ raise IdentityJwksError('Invalid Identity JWT.') from exc
160
+ return claims