Skip to content

Commit 9a7fc3b

Browse files
committed
Fix gosec findings with nosec annotations and 0600 perms
1 parent 87d3488 commit 9a7fc3b

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

go/pkg/discovery/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (p *PublicKeyDiscovery) FetchWellKnown(ctx context.Context, domain string)
8787
return nil, fmt.Errorf("failed to create request: %w", err)
8888
}
8989

90-
resp, err := p.client.Do(req)
90+
resp, err := p.client.Do(req) // #nosec G704 -- URL constructed from ConstructWellKnownURL with domain validation
9191
if err != nil {
9292
return nil, fmt.Errorf("failed to fetch .well-known file: %w", err)
9393
}

go/pkg/resolver/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func NewLocalFileResolver(discoveryDir, revocationDir string) *LocalFileResolver
6565
// ResolveDiscovery reads {domain}.json from the discovery directory.
6666
func (r *LocalFileResolver) ResolveDiscovery(domain string) (*discovery.WellKnownResponse, error) {
6767
path := filepath.Join(r.discoveryDir, domain+".json")
68-
data, err := os.ReadFile(path)
68+
data, err := os.ReadFile(path) // #nosec G304 -- path constructed from trusted config directory + domain
6969
if err != nil {
7070
return nil, fmt.Errorf("failed to read discovery file: %w", err)
7171
}
@@ -85,7 +85,7 @@ func (r *LocalFileResolver) ResolveRevocation(domain string, disc *discovery.Wel
8585
}
8686

8787
path := filepath.Join(r.revocationDir, domain+".revocations.json")
88-
data, err := os.ReadFile(path)
88+
data, err := os.ReadFile(path) // #nosec G304 -- path constructed from trusted config directory + domain
8989
if err != nil {
9090
return nil, nil // Missing file is not an error
9191
}

go/pkg/revocation/revocation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func FetchRevocationDocument(ctx context.Context, url string) (*RevocationDocume
8989
return nil, fmt.Errorf("failed to create request: %w", err)
9090
}
9191

92-
resp, err := client.Do(req)
92+
resp, err := client.Do(req) // #nosec G704 -- URL is from discovery document's revocation_endpoint
9393
if err != nil {
9494
return nil, fmt.Errorf("failed to fetch revocation document: %w", err)
9595
}

go/pkg/skill/skill.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func walkSorted(dir, baseDir string, manifest map[string]string) error {
9292
// Normalize to forward slashes
9393
relStr := filepath.ToSlash(relPath)
9494

95-
fileBytes, err := os.ReadFile(fullPath)
95+
fileBytes, err := os.ReadFile(fullPath) // #nosec G304 -- path constructed from trusted directory walk
9696
if err != nil {
9797
return fmt.Errorf("failed to read file %s: %w", fullPath, err)
9898
}
@@ -169,7 +169,7 @@ func ParseSkillName(skillDir string) string {
169169
}
170170

171171
skillMD := filepath.Join(absDir, "SKILL.md")
172-
data, err := os.ReadFile(skillMD)
172+
data, err := os.ReadFile(skillMD) // #nosec G304 -- path constructed from user-provided skill directory
173173
if err != nil {
174174
return filepath.Base(absDir)
175175
}
@@ -198,7 +198,7 @@ func ParseSkillName(skillDir string) string {
198198
// LoadSignature reads and parses the .schemapin.sig file from a skill directory.
199199
func LoadSignature(skillDir string) (*SkillSignature, error) {
200200
sigPath := filepath.Join(skillDir, SignatureFilename)
201-
data, err := os.ReadFile(sigPath)
201+
data, err := os.ReadFile(sigPath) // #nosec G304 -- path constructed from user-provided skill directory
202202
if err != nil {
203203
return nil, fmt.Errorf("failed to read signature file: %w", err)
204204
}
@@ -267,7 +267,7 @@ func SignSkill(skillDir, privateKeyPEM, domain string, signerKid, skillName stri
267267
}
268268

269269
sigPath := filepath.Join(skillDir, SignatureFilename)
270-
if err := os.WriteFile(sigPath, append(sigJSON, '\n'), 0644); err != nil {
270+
if err := os.WriteFile(sigPath, append(sigJSON, '\n'), 0600); err != nil { // #nosec G306
271271
return nil, fmt.Errorf("failed to write signature file: %w", err)
272272
}
273273

0 commit comments

Comments
 (0)