Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /poc /backend /app /models /vulnerability.py
| """ | |
| Vulnerability model for findings management. | |
| """ | |
| import uuid | |
| from datetime import datetime, timezone | |
| from enum import Enum as PyEnum | |
| from sqlalchemy import ( | |
| JSON, | |
| Column, | |
| DateTime, | |
| Enum, | |
| ForeignKey, | |
| Numeric, | |
| String, | |
| Text, | |
| ) | |
| from sqlalchemy.dialects.postgresql import ARRAY, UUID | |
| from sqlalchemy.orm import relationship | |
| from app.core.database import Base | |
| class Severity(str, PyEnum): | |
| """Severity levels.""" | |
| CRITICAL = "critical" | |
| HIGH = "high" | |
| MEDIUM = "medium" | |
| LOW = "low" | |
| INFO = "info" | |
| class VulnerabilityStatus(str, PyEnum): | |
| """Vulnerability status.""" | |
| OPEN = "open" | |
| IN_PROGRESS = "in_progress" | |
| RESOLVED = "resolved" | |
| FALSE_POSITIVE = "false_positive" | |
| RISK_ACCEPTED = "risk_accepted" | |
| class Vulnerability(Base): | |
| """Vulnerability model.""" | |
| __tablename__ = "vulnerabilities" | |
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | |
| scan_id = Column(UUID(as_uuid=True), ForeignKey("scans.id"), nullable=False) | |
| # Basic information | |
| name = Column(String(500), nullable=False) | |
| description = Column(Text, nullable=False) | |
| severity = Column(Enum(Severity), nullable=False) | |
| cvss_score = Column(Numeric(3, 1), nullable=True) | |
| cvss_vector = Column(String(100), nullable=True) | |
| # Classification | |
| cve_id = Column(String(50), nullable=True, index=True) | |
| cwe_id = Column(String(50), nullable=True) | |
| owasp_category = Column(String(100), nullable=True) | |
| # Details | |
| proof_of_concept = Column(Text, nullable=True) | |
| remediation = Column(Text, nullable=False) | |
| references = Column(ARRAY(String), default=list, nullable=False) | |
| # Affected hosts | |
| affected_hosts = Column(JSON, default=list, nullable=False) | |
| # Tags | |
| tags = Column(ARRAY(String), default=list, nullable=False) | |
| # Status tracking | |
| status = Column( | |
| Enum(VulnerabilityStatus), | |
| default=VulnerabilityStatus.OPEN, | |
| nullable=False, | |
| ) | |
| assigned_to = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True) | |
| verified_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True) | |
| verified_at = Column(DateTime(timezone=True), nullable=True) | |
| false_positive_reason = Column(Text, nullable=True) | |
| # Timestamps | |
| created_at = Column( | |
| DateTime(timezone=True), | |
| default=lambda: datetime.now(timezone.utc), | |
| nullable=False, | |
| ) | |
| updated_at = Column( | |
| DateTime(timezone=True), | |
| default=lambda: datetime.now(timezone.utc), | |
| onupdate=lambda: datetime.now(timezone.utc), | |
| nullable=False, | |
| ) | |
| # Relationships | |
| scan = relationship("Scan", back_populates="vulnerabilities") | |
| assigned_user = relationship("User", foreign_keys=[assigned_to], back_populates="vulnerabilities") | |
| verifier = relationship("User", foreign_keys=[verified_by]) | |
| def __repr__(self): | |
| return f"<Vulnerability(id={self.id}, name={self.name}, severity={self.severity})>" | |
| def to_dict(self): | |
| """Convert to dictionary.""" | |
| return { | |
| "id": str(self.id), | |
| "scanId": str(self.scan_id), | |
| "name": self.name, | |
| "description": self.description, | |
| "severity": self.severity.value, | |
| "cvssScore": float(self.cvss_score) if self.cvss_score else None, | |
| "cvssVector": self.cvss_vector, | |
| "cveId": self.cve_id, | |
| "cweId": self.cwe_id, | |
| "owaspCategory": self.owasp_category, | |
| "proofOfConcept": self.proof_of_concept, | |
| "remediation": self.remediation, | |
| "references": self.references, | |
| "affectedHosts": self.affected_hosts, | |
| "tags": self.tags, | |
| "status": self.status.value, | |
| "assignedTo": str(self.assigned_to) if self.assigned_to else None, | |
| "verifiedBy": str(self.verified_by) if self.verified_by else None, | |
| "verifiedAt": (self.verified_at.isoformat() if self.verified_at else None), | |
| "falsePositiveReason": self.false_positive_reason, | |
| "createdAt": (self.created_at.isoformat() if self.created_at else None), | |
| "updatedAt": (self.updated_at.isoformat() if self.updated_at else None), | |
| } | |
Xet Storage Details
- Size:
- 4.27 kB
- Xet hash:
- 4f167c0d11f004c9c39f7f6482be8d86b455736dfc7de522cde4efeacecd27ee
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.