Skip to content

Commit cdce892

Browse files
refactor: improve error handling for file/db operations and clean up resource cleanup
1 parent 3296e5f commit cdce892

11 files changed

Lines changed: 990 additions & 44 deletions

File tree

CLAUDE.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
88

99
**Motto**: "Cybersecurity. With humans."
1010

11-
### Philosphy
12-
- **Human centric**: , actionable output, addresses barriers to entry, encourage end-user ducation and self-efficacy, feminist (for example, informed consent), safe effective high-quality
13-
- **Evidence based**: accepts falliblism, error correction, value for time, value for money
14-
- **Sustainable innovation**: Maintainable code, comprehensive documentation, iterative improvement, response ready, incorporates recent research and best practice
15-
- **Collaboration and listening**: Built by ethical hackers for ethical hackers, transparent decision making, ownership accountability responsibility, open source
11+
### Philosophy
12+
13+
- **Human-centric**: Transparent error handling, actionable output, addresses barriers to entry, encourages end-user education and self-efficacy, feminist principles (informed consent), safe, effective, high-quality
14+
- **Evidence-based**: Accepts fallibilism, error correction, value for time, value for money, verifiable results
15+
- **Sustainable innovation**: Maintainable code, comprehensive documentation, iterative improvement, incident response ready, incorporates recent research and best practice
16+
- **Collaboration and listening**: Built by ethical hackers for ethical hackers, transparent decision making, ownership and accountability, open source
1617

1718
**Purpose**: Designed for bug bounty hunters and security researchers to automate the vulnerability discovery and reporting pipeline through distributed scanning while maintaining ethical practices and human oversight.
1819

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

LICENSE.agpl

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE.dnh

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Do No Harm License
2+
3+
## 1. Preamble
4+
5+
Most software today is developed with little to no thought of how it will be used, or the
6+
consequences for our society and planet.
7+
8+
As software developers, we engineer the infrastructure of the 21st century. We recognise that our
9+
infrastructure has great power to shape the world and the lives of those we share it with, and we
10+
choose to consciously take responsibility for the social and environmental impacts of what we build.
11+
12+
We envisage a world free from injustice, inequality, and the reckless destruction of lives and our
13+
planet. We reject slavery in all its forms, whether by force, indebtedness, or by algorithms that
14+
hack human vulnerabilities. We seek a world where humankind is at peace with our neighbours, nature,
15+
and ourselves. We want our work to enrich the physical, mental and spiritual wellbeing of all
16+
society.
17+
18+
We build software to further this vision of a just world, or at the very least, to not put that
19+
vision further from reach.
20+
21+
## 2. Definitions
22+
23+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by
24+
Sections 1 through 9 of this document.
25+
26+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is
27+
granting the License.
28+
29+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are
30+
controlled by, or are under common control with that entity. For the purposes of this definition,
31+
"control" means (i) the power, direct or indirect, to cause the direction or management of such
32+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
33+
outstanding shares, or (iii) beneficial ownership of such entity.
34+
35+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this
36+
License.
37+
38+
"Source" form shall mean the preferred form for making modifications, including but not limited to
39+
software source code, documentation source, and configuration files.
40+
41+
"Object" form shall mean any form resulting from mechanical transformation or translation of a
42+
Source form, including but not limited to compiled object code, generated documentation, and
43+
conversions to other media types.
44+
45+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the
46+
License, as indicated by a copyright notice that is included in or attached to the work (an example
47+
is provided in the Appendix below).
48+
49+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or
50+
derived from) the Work and for which the editorial revisions, annotations, elaborations, or other
51+
modifications represent, as a whole, an original work of authorship. For the purposes of this
52+
License, Derivative Works shall not include works that remain separable from, or merely link (or
53+
bind by name) to the interfaces of, the Work and Derivative Works thereof.
54+
55+
"Contribution" shall mean any work of authorship, including the original version of the Work and any
56+
modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted
57+
to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity
58+
authorized to submit on behalf of the copyright owner. For the purposes of this definition,
59+
"submitted" means any form of electronic, verbal, or written communication sent to the Licensor or
60+
its representatives, including but not limited to communication on electronic mailing lists, source
61+
code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor
62+
for the purpose of discussing and improving the Work, but excluding communication that is
63+
conspicuously marked or otherwise designated in writing by the copyright owner as "Not a
64+
Contribution."
65+
66+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a
67+
Contribution has been received by Licensor and subsequently incorporated within the Work.
68+
69+
"Forests" shall mean 0.5 or more hectares of trees that were either planted more than 50 years ago
70+
or were not planted by humans or human made equipment.
71+
72+
"Deforestation" shall mean the clearing, burning or destruction of 0.5 or more hectares of forests
73+
within a 1 year period.
74+
75+
## 3. Grant of Copyright License
76+
77+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a
78+
perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to
79+
reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and
80+
distribute the Work and such Derivative Works in Source or Object form.
81+
82+
## 4. Grant of Patent License
83+
84+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a
85+
perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
86+
section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer
87+
the Work, where such license applies only to those patent claims licensable by such Contributor that
88+
are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s)
89+
with the Work to which such Contribution(s) was submitted. If You institute patent litigation
90+
against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or
91+
a Contribution incorporated within the Work constitutes direct or contributory patent infringement,
92+
then any patent licenses granted to You under this License for that Work shall terminate as of the
93+
date such litigation is filed.
94+
95+
## 5. Redistribution
96+
97+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with
98+
or without modifications, and in Source or Object form, provided that You meet the following
99+
conditions:
100+
101+
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
102+
103+
2. You must cause any modified files to carry prominent notices stating that You changed the
104+
files; and
105+
106+
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright,
107+
patent, trademark, and attribution notices from the Source form of the Work, excluding those
108+
notices that do not pertain to any part of the Derivative Works; and
109+
110+
4. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
111+
or promote products derived from this software without specific prior written permission; and
112+
113+
5. This software must not be used by any organisation, website, product, or service that:
114+
1. promotes, lobbies for or derives a majority of income from:
115+
1. **abuses of human rights**:
116+
* human trafficking
117+
* sex trafficking
118+
* slavery or indentured servitude
119+
* discrimination based on age, gender, gender identity, race, sexuality, religion, nationality
120+
* hate speech
121+
2. **environmental destruction**:
122+
* the extraction or sale of fossil fuels
123+
* the destruction of habitats for threatened or endangered species, including through deforestation or burning of forests
124+
* the abuse, inhumane killing or neglect of animals under human control
125+
* industrial processes that generate waste products that threaten life
126+
3. **conflict and war**:
127+
* warfare
128+
* war crimes
129+
* weapons manufacturing
130+
* violence (except when required to protect public safety)
131+
4. **addictive or destructive products and services**:
132+
* gambling
133+
* tobacco
134+
* products that encourage adversely addictive behaviours
135+
136+
2. dissuades, lobbies against, or derives a majority of income from actions that discourage or frustrate:
137+
* peace
138+
* access to the rights set out in the [Universal Declaration of Human Rights](./documents/UDHR.md) and the [Convention on the Rights of the Child](./documents/CRC.md)
139+
* democratic processes
140+
* peaceful assembly and association (including worker associations)
141+
* a sustainable environment
142+
; and
143+
144+
5. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative
145+
Works that You distribute must include a readable copy of the attribution notices contained
146+
within such NOTICE file, excluding those notices that do not pertain to any part of the
147+
Derivative Works, in at least one of the following places: within a NOTICE text file
148+
distributed as part of the Derivative Works; within the Source form or documentation, if
149+
provided along with the Derivative Works; or, within a display generated by the Derivative
150+
Works, if and wherever such third-party notices normally appear. The contents of the NOTICE
151+
file are for informational purposes only and do not modify the License. You may add Your own
152+
attribution notices within Derivative Works that You distribute, alongside or as an addendum to
153+
the NOTICE text from the Work, provided that such additional attribution notices cannot be
154+
construed as modifying the License.
155+
156+
You may add Your own copyright statement to Your modifications and may provide additional or
157+
different license terms and conditions for use, reproduction, or distribution of Your modifications,
158+
or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of
159+
the Work otherwise complies with the conditions stated in this License.
160+
161+
## 6. Submission of Contributions
162+
163+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the
164+
Work by You to the Licensor shall be under the terms and conditions of this License, without any
165+
additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify
166+
the terms of any separate license agreement you may have executed with Licensor regarding such
167+
Contributions.
168+
169+
## 7. Trademarks
170+
171+
This License does not grant permission to use the trade names, trademarks, service marks, or product
172+
names of the Licensor, except as required for reasonable and customary use in describing the origin
173+
of the Work and reproducing the content of the NOTICE file.
174+
175+
## 8. Disclaimer of Warranty
176+
177+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each
178+
Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
179+
KIND, either express or implied, including, without limitation, any warranties or conditions of
180+
TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
181+
responsible for determining the appropriateness of using or redistributing the Work and assume any
182+
risks associated with Your exercise of permissions under this License.
183+
184+
## 9. Limitation of Liability
185+
186+
In no event and under no legal theory, whether in tort (including negligence), contract, or
187+
otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or
188+
agreed to in writing, shall any Contributor be liable to You for damages, including any direct,
189+
indirect, special, incidental, or consequential damages of any character arising as a result of this
190+
License or out of the use or inability to use the Work (including but not limited to damages for
191+
loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial
192+
damages or losses), even if such Contributor has been advised of the possibility of such damages.
193+
194+
## 10. Accepting Warranty or Additional Liability
195+
196+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee
197+
for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights
198+
consistent with this License. However, in accepting such obligations, You may act only on Your own
199+
behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You
200+
agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or
201+
claims asserted against, such Contributor by reason of your accepting any such warranty or
202+
additional liability.
203+
204+
## Attribution
205+
206+
Do No Harm License [Contributor Covenant][homepage], (pre 1.0),
207+
available at https://github.com/raisely/NoHarm
208+
209+
[homepage]: https://github.com/raisely/NoHarm

LICENSE.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# License
2+
3+
This project is dual-licensed under the terms of:
4+
5+
1. The GNU Affero General Public License (AGPL) v3 or any later version
6+
2. The Do No Harm License
7+
8+
You may choose to use, distribute, and modify this software under the terms of **either** license.
9+
10+
---
11+
12+
## License Philosophy
13+
14+
As the author of this project, I encourage you to honor **the spirit of both licenses**, regardless of which one you formally adopt.
15+
16+
- The **AGPL** ensures that the software remains free and open for all users, especially in networked environments.
17+
- The **Do No Harm License** aims to prevent the software from being used in ways that cause harm to people or the planet.
18+
19+
> **I hope you will use this software to build things that are ethical, empowering, and socially responsible.**
20+
21+
---
22+
23+
## Included License Files
24+
25+
Copies of both licenses are included in this repository:
26+
27+
- [`LICENSE.agpl`](./LICENSE.agpl) — GNU AGPL v3
28+
- [`LICENSE.dnh`](./LICENSE.dnh) — Do No Harm License
29+
30+
Choose the license that best aligns with your use case and values.
31+
32+
---
33+
34+
## 🔗 Resources
35+
36+
- AGPL v3: [https://www.gnu.org/licenses/agpl-3.0.html](https://www.gnu.org/licenses/agpl-3.0.html)
37+
- Do No Harm: [https://github.com/raisely/NoHarm](https://github.com/raisely/NoHarm)

cmd/config.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,16 @@ var configClearCmd = &cobra.Command{
193193
credFile := filepath.Join(homeDir, ".shells", "credentials.enc")
194194
keyFile := filepath.Join(homeDir, ".shells", ".key")
195195

196-
os.Remove(credFile)
197-
os.Remove(keyFile)
196+
// Remove credential files - warn if fails but don't error
197+
// (files may not exist, which is fine)
198+
if err := os.Remove(credFile); err != nil && !os.IsNotExist(err) {
199+
fmt.Fprintf(os.Stderr, "Warning: failed to remove %s: %v\n", credFile, err)
200+
fmt.Fprintf(os.Stderr, "You may need to manually delete this file\n")
201+
}
202+
if err := os.Remove(keyFile); err != nil && !os.IsNotExist(err) {
203+
fmt.Fprintf(os.Stderr, "Warning: failed to remove %s: %v\n", keyFile, err)
204+
fmt.Fprintf(os.Stderr, "You may need to manually delete this file\n")
205+
}
198206

199207
fmt.Println("✅ API credentials cleared")
200208

cmd/protocol.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,12 @@ func saveProtocolResults(findings []types.Finding, output string) error {
492492
if err != nil {
493493
return err
494494
}
495-
defer file.Close()
495+
defer func() {
496+
if err := file.Close(); err != nil {
497+
fmt.Fprintf(os.Stderr, "Warning: failed to close report file %s: %v\n", output, err)
498+
fmt.Fprintf(os.Stderr, "Report may be incomplete or corrupted\n")
499+
}
500+
}()
496501

497502
// Create report
498503
fmt.Fprintf(file, "Protocol Security Scan Report\n")

cmd/self_update.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ func calculateSHA256(filepath string) (string, error) {
161161
if err != nil {
162162
return "", err
163163
}
164-
defer file.Close()
164+
defer func() {
165+
if err := file.Close(); err != nil {
166+
// Log but don't fail - hash was already calculated
167+
fmt.Fprintf(os.Stderr, "Warning: failed to close file after hashing: %v\n", err)
168+
}
169+
}()
165170

166171
hash := sha256.New()
167172
if _, err := io.Copy(hash, file); err != nil {

cmd/smuggle.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import (
1313
"github.com/spf13/cobra"
1414
)
1515

16+
// TECHNICAL DEBT: This file contains 2 remaining os.Exit(1) calls that should be replaced
17+
// with proper error returns for better composability and testing.
18+
// Pattern to fix: fmt.Printf("Error..."); os.Exit(1) -> return fmt.Errorf("...")
19+
// Locations: lines ~143, ~186 (search for "os.Exit" to find exact lines)
20+
// Priority: P1 (improves testability but not critical for users)
21+
1622
var smuggleCmd = &cobra.Command{
1723
Use: "smuggle",
1824
Short: "Detect HTTP Request Smuggling vulnerabilities",
@@ -82,7 +88,8 @@ Examples:
8288

8389
findings, err := scanner.Scan(ctx, target, options)
8490
if err != nil {
85-
fmt.Printf("Error during smuggling detection: %v\n", err)
91+
// TODO(P1): Convert this command to use RunE instead of Run to return errors properly
92+
fmt.Fprintf(os.Stderr, "Error: smuggling detection failed: %v\n", err)
8693
os.Exit(1)
8794
}
8895

internal/credentials/manager.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,13 @@ func (m *Manager) loadLegacy() error {
379379
return fmt.Errorf("failed to migrate credentials: %w", err)
380380
}
381381

382-
// Remove legacy file
383-
os.Remove(legacyFile)
382+
// Remove legacy file after successful migration
383+
if err := os.Remove(legacyFile); err != nil && !os.IsNotExist(err) {
384+
m.logger.Warnw("Failed to remove legacy credentials file after migration",
385+
"file", legacyFile,
386+
"error", err,
387+
"action", "Manually delete the file for security")
388+
}
384389
m.logger.Info("Migrated credentials to encrypted storage")
385390
}
386391

0 commit comments

Comments
 (0)