Skip to content

Commit 3bb9bff

Browse files
fix: add error handling for flag parsing, JSON marshaling and report validation
1 parent 061c771 commit 3bb9bff

6 files changed

Lines changed: 65 additions & 28 deletions

File tree

cmd/platform.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ var platformProgramsCmd = &cobra.Command{
4242
Use: "programs",
4343
Short: "List available bug bounty programs",
4444
RunE: func(cmd *cobra.Command, args []string) error {
45-
// P0-2: TODO: Fix silent error suppression - check flag parsing errors
46-
platform, _ := cmd.Flags().GetString("platform")
47-
output, _ := cmd.Flags().GetString("output")
45+
// P0-2 FIX: Check flag parsing errors
46+
platform, err := cmd.Flags().GetString("platform")
47+
if err != nil {
48+
return fmt.Errorf("invalid --platform flag: %w", err)
49+
}
50+
output, err := cmd.Flags().GetString("output")
51+
if err != nil {
52+
return fmt.Errorf("invalid --output flag: %w", err)
53+
}
4854

4955
client, err := getPlatformClient(platform)
5056
if err != nil {
@@ -60,8 +66,11 @@ var platformProgramsCmd = &cobra.Command{
6066
}
6167

6268
if output == "json" {
63-
// P0-3: TODO: Fix silent error suppression - check JSON marshaling errors
64-
jsonData, _ := json.MarshalIndent(programs, "", " ")
69+
// P0-3 FIX: Check JSON marshaling errors
70+
jsonData, err := json.MarshalIndent(programs, "", " ")
71+
if err != nil {
72+
return fmt.Errorf("failed to marshal programs to JSON: %w", err)
73+
}
6574
fmt.Println(string(jsonData))
6675
} else {
6776
printPrograms(programs)
@@ -77,10 +86,19 @@ var platformSubmitCmd = &cobra.Command{
7786
Args: cobra.ExactArgs(1),
7887
RunE: func(cmd *cobra.Command, args []string) error {
7988
findingID := args[0]
80-
// P0-2: TODO: Fix silent error suppression - check flag parsing errors
81-
platform, _ := cmd.Flags().GetString("platform")
82-
programHandle, _ := cmd.Flags().GetString("program")
83-
dryRun, _ := cmd.Flags().GetBool("dry-run")
89+
// P0-2 FIX: Check flag parsing errors
90+
platform, err := cmd.Flags().GetString("platform")
91+
if err != nil {
92+
return fmt.Errorf("invalid --platform flag: %w", err)
93+
}
94+
programHandle, err := cmd.Flags().GetString("program")
95+
if err != nil {
96+
return fmt.Errorf("invalid --program flag: %w", err)
97+
}
98+
dryRun, err := cmd.Flags().GetBool("dry-run")
99+
if err != nil {
100+
return fmt.Errorf("invalid --dry-run flag: %w", err)
101+
}
84102

85103
store := GetStore()
86104
if store == nil {
@@ -112,7 +130,10 @@ var platformSubmitCmd = &cobra.Command{
112130

113131
if dryRun {
114132
log.Info("DRY RUN - Report would be submitted:", "component", "platform")
115-
reportJSON, _ := json.MarshalIndent(report, "", " ")
133+
reportJSON, err := json.MarshalIndent(report, "", " ")
134+
if err != nil {
135+
return fmt.Errorf("failed to marshal report to JSON: %w", err)
136+
}
116137
fmt.Println(string(reportJSON))
117138
return nil
118139
}

pkg/auth/common/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ type Finding struct {
110110
CreatedAt time.Time `json:"created_at"`
111111
}
112112

113+
// TestResult represents the result of a single security test
114+
type TestResult struct {
115+
Name string `json:"name"`
116+
Protocol AuthProtocol `json:"protocol"`
117+
Vulnerable bool `json:"vulnerable"`
118+
Severity string `json:"severity"`
119+
Description string `json:"description"`
120+
Evidence []Evidence `json:"evidence,omitempty"`
121+
ExecutedAt time.Time `json:"executed_at"`
122+
}
123+
113124
// AuthReport represents the main authentication report
114125
type AuthReport struct {
115126
Target string `json:"target"`
@@ -118,6 +129,7 @@ type AuthReport struct {
118129
Configuration AuthConfiguration `json:"configuration"`
119130
Vulnerabilities []Vulnerability `json:"vulnerabilities"`
120131
AttackChains []AttackChain `json:"attack_chains"`
132+
Tests []TestResult `json:"tests"` // Individual test results for audit trail
121133
Summary ReportSummary `json:"summary"`
122134
Protocols map[string]interface{} `json:"protocols"`
123135
}

pkg/platforms/aws/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ func (c *Client) GetProgramByHandle(ctx context.Context, handle string) (*platfo
6969

7070
// Submit submits a vulnerability report to AWS VRP via HackerOne
7171
func (c *Client) Submit(ctx context.Context, report *platforms.VulnerabilityReport) (*platforms.SubmissionResponse, error) {
72-
// P0-4: TODO: Add validation call here
73-
// if err := report.Validate(); err != nil {
74-
// return nil, fmt.Errorf("invalid report: %w", err)
75-
// }
76-
7772
// Ensure the report is for the AWS program
7873
if report.ProgramHandle == "" {
7974
report.ProgramHandle = c.config.ProgramHandle
8075
}
8176

77+
// P0-4 FIX: Validate report before submission
78+
if err := report.Validate(); err != nil {
79+
return nil, fmt.Errorf("invalid report: %w", err)
80+
}
81+
8282
// Add AWS-specific context to the report
8383
awsContext := fmt.Sprintf("\n\n---\n**AWS Service**: %s\n**Region**: %s\n**Account Type**: %s",
8484
getServiceFromAsset(report.AssetURL),

pkg/platforms/azure/client.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,26 @@ func (c *Client) Submit(ctx context.Context, report *platforms.VulnerabilityRepo
125125
// For now, we return the formatted report
126126
reportID := fmt.Sprintf("azure-%d", time.Now().Unix())
127127

128-
// P0-5: TODO: This should return Success: false since report is NOT actually submitted
129-
// User must manually email the report. Currently misleading users that it's submitted.
128+
// P0-5 FIX: Report is NOT automatically submitted - user must manually send email
129+
// Success: false to indicate manual action required
130130
return &platforms.SubmissionResponse{
131-
Success: true, // TODO: Change to false - report is not actually submitted!
131+
Success: false, // CRITICAL: Report is NOT submitted - user must manually email
132132
ReportID: reportID,
133133
ReportURL: "mailto:" + c.config.ReportingEmail + "?subject=" +
134134
fmt.Sprintf("Azure Security Vulnerability: %s", report.Title) +
135135
"&body=" + emailBody,
136-
Status: "pending_email", // TODO: Change to "pending_manual_email"
137-
Message: fmt.Sprintf("Report formatted for email submission to %s", c.config.ReportingEmail), // TODO: Add warning that manual action required
136+
Status: "requires_manual_email", // User must click mailto link or copy email body
137+
Message: fmt.Sprintf("⚠️ MANUAL ACTION REQUIRED: Report formatted but NOT submitted.\n"+
138+
"Please click the mailto: link above or manually email the report to %s\n"+
139+
"The email body has been formatted according to MSRC guidelines.",
140+
c.config.ReportingEmail),
138141
SubmittedAt: time.Now(),
139142
PlatformData: map[string]interface{}{
140143
"reporting_email": c.config.ReportingEmail,
141144
"program_type": c.config.ProgramType,
142145
"severity": severity,
143146
"email_body": emailBody,
147+
"requires_manual_submission": true,
144148
},
145149
}, nil
146150
}

pkg/platforms/bugcrowd/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ func (c *Client) GetProgramByHandle(ctx context.Context, handle string) (*platfo
135135

136136
// Submit submits a vulnerability report to Bugcrowd
137137
func (c *Client) Submit(ctx context.Context, report *platforms.VulnerabilityReport) (*platforms.SubmissionResponse, error) {
138-
// P0-4: TODO: Add validation call here
139-
// if err := report.Validate(); err != nil {
140-
// return nil, fmt.Errorf("invalid report: %w", err)
141-
// }
138+
// P0-4 FIX: Validate report before submission
139+
if err := report.Validate(); err != nil {
140+
return nil, fmt.Errorf("invalid report: %w", err)
141+
}
142142

143143
// Map severity to Bugcrowd priority format (P1-P5)
144144
mapping := platforms.GetSeverityMapping("bugcrowd")

pkg/platforms/hackerone/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ func (c *Client) GetProgramByHandle(ctx context.Context, handle string) (*platfo
130130

131131
// Submit submits a vulnerability report to HackerOne
132132
func (c *Client) Submit(ctx context.Context, report *platforms.VulnerabilityReport) (*platforms.SubmissionResponse, error) {
133-
// P0-4: TODO: Add validation call here
134-
// if err := report.Validate(); err != nil {
135-
// return nil, fmt.Errorf("invalid report: %w", err)
136-
// }
133+
// P0-4 FIX: Validate report before submission
134+
if err := report.Validate(); err != nil {
135+
return nil, fmt.Errorf("invalid report: %w", err)
136+
}
137137

138138
// Map severity to HackerOne format
139139
mapping := platforms.GetSeverityMapping("hackerone")

0 commit comments

Comments
 (0)