@@ -60,13 +60,19 @@ def _text(value: Any, limit: int = 512) -> str:
6060 if any (unicodedata .category (char ).startswith ("C" ) for char in value ) or normalized_size > limit :
6161 raise IdentityError ("invalid text" )
6262 return value
63+ def _secret_marker (value : str ) -> bool :
64+ return any (pattern .search (value ) for pattern in SECRET_PATTERNS )
6365def _scope (value : Any ) -> dict [str , str ]:
6466 scope = _obj (value , {"repo" , "file" , "category" })
6567 repo = _text (scope ["repo" ], 140 )
68+ if _secret_marker (repo ):
69+ raise IdentityError ("reserved secret marker" )
6670 parts = repo .split ("/" )
6771 if len (parts ) != 2 or not OWNER .fullmatch (parts [0 ]) or "--" in parts [0 ] or not REPO .fullmatch (parts [1 ]) or parts [1 ] in {"." , ".." }:
6872 raise IdentityError ("invalid repo" )
6973 path = _text (scope ["file" ], 1024 )
74+ if _secret_marker (path ):
75+ raise IdentityError ("reserved secret marker" )
7076 if path .startswith ("/" ) or "\\ " in path or any (part in {"" , "." , ".." } for part in path .split ("/" )):
7177 raise IdentityError ("invalid path" )
7278 category = _text (scope ["category" ], 32 )
@@ -81,13 +87,13 @@ def _token(value: Any) -> dict[str, Any]:
8187 if kind == "secret_ref" :
8288 ref = _obj (token ["value" ], {"type" , "role" , "position" })
8389 typ , role , position = _text (ref ["type" ], 32 ), _text (ref ["role" ], 32 ), ref ["position" ]
84- if any (pattern . search (candidate ) for pattern in SECRET_PATTERNS for candidate in (typ , role )):
90+ if any (_secret_marker (candidate ) for candidate in (typ , role )):
8591 raise IdentityError ("reserved secret marker" )
8692 if not re .fullmatch (r"[a-z][a-z0-9_.-]{0,31}" , typ ) or not re .fullmatch (r"[a-z][a-z0-9_.-]{0,31}" , role ) or isinstance (position , bool ) or not isinstance (position , int ) or not 0 <= position <= 1024 :
8793 raise IdentityError ("invalid secret reference" )
8894 return {"kind" : kind , "value" : {"type" : typ , "role" : role , "position" : position }}
8995 item = _text (token ["value" ])
90- if any ( pattern . search ( item ) for pattern in SECRET_PATTERNS ):
96+ if _secret_marker ( item ):
9197 raise IdentityError ("reserved secret marker" )
9298 if kind == "operator" and item not in OPS or kind == "policy_state" and item not in POLICY or kind == "identifier" and not IDENTIFIER .fullmatch (item ):
9399 raise IdentityError ("invalid typed token" )
0 commit comments