Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions capiscio_sdk/validators/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,27 @@ def validate_signature(
import jwt

# Verify signature
jwt.decode(
decoded = jwt.decode(
signature,
public_key,
algorithms=['RS256', 'ES256', 'PS256'],
options={"verify_signature": True}
)

# Signature is valid
logger.debug("Signature verified successfully")
# Bind: compare decoded payload against caller-supplied payload
if decoded != payload:
issues.append(
ValidationIssue(
severity=ValidationSeverity.ERROR,
code="PAYLOAD_MISMATCH",
message="Decoded signature payload does not match the supplied payload",
path="signatures",
)
)
score = 0
else:
# Signature is valid and payload matches
logger.debug("Signature verified successfully")

except jwt.InvalidSignatureError:
issues.append(
Expand Down Expand Up @@ -156,12 +168,12 @@ def validate_signature(
issues.append(
ValidationIssue(
severity=ValidationSeverity.WARNING,
code="NO_PUBLIC_KEY",
message="Signature format valid but no public key provided for verification",
code="UNVERIFIED_FORMAT_OK",
message="Signature format valid but cryptographic verification not performed (no public key provided)",
path="signatures",
)
)
Comment on lines +171 to 175
Comment on lines +171 to 175
score = 70 # Format is OK but not verified
score = 50 # Format-only: below success threshold
Comment on lines +172 to +176

# Ensure score doesn't go negative
score = max(0, score)
Expand Down
Loading