Skip to content

GLEIF lookups could panic on nil HTTP responses under network/error edge cases, causing datasource instability in org enrichment paths. This change hardens response handling and adds deterministic regression coverage for the nil-response path.#1112

Open
MichaelMVS wants to merge 4 commits intoowasp-amass:mainfrom
MichaelMVS:main

Conversation

@MichaelMVS
Copy link
Copy Markdown

Problem:
GLEIF helper methods could panic with a nil-pointer dereference when HTTP requests returned a nil response object and response fields were accessed without nil checks.

Solution:
Added an injectable request function (requestWebPage) for deterministic tests and added explicit nil-response guards in GLEIF fuzzy, LEI, direct-parent, and direct-children retrieval paths. Returned explicit errors when responses are nil/invalid instead of dereferencing.

Testing:

go test ./engine/plugins/support/org -run 'TestGLEIFGet(LEIRecord|DirectParentRecord|DirectChildrenRecords)NilResponseNoPanic'
go test ./engine/plugins/support/org
go test ./... (best effort; environment may fail on missing libpostal / external network tests)

Copilot AI and others added 4 commits March 20, 2026 17:41
Co-authored-by: MichaelMVS <102698294+MichaelMVS@users.noreply.github.com>
Agent-Logs-Url: https://github.com/MichaelMVS/amass/sessions/ce85891c-4f57-4f7b-adb5-1c4be1e87132
…urces

Fix GLEIF nil-response panic in org support helpers
Copilot AI review requested due to automatic review settings March 21, 2026 04:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens the org enrichment GLEIF helper functions against nil HTTP responses (preventing nil-pointer panics) and adds regression tests for the nil-response edge case.

Changes:

  • Introduces an injectable requestWebPage function for deterministic testing of GLEIF HTTP behavior.
  • Adds explicit nil/invalid response guards in GLEIF fuzzy, LEI, direct-parent, and direct-children retrieval paths.
  • Adds regression tests ensuring no panic occurs when the HTTP layer returns (nil, nil).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
engine/plugins/support/org/gleif.go Uses an injectable request function and adds nil/invalid response handling to prevent panics.
engine/plugins/support/org/gleif_nil_response_test.go Adds deterministic tests covering nil HTTP responses for several GLEIF retrieval helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +37 to +43
if err != nil {
msg := fmt.Sprintf("Failed to obtain the LEI record for %s: %s", name, err)
return nil, fmt.Errorf("GLEIFSearchFuzzyCompletions: %s", msg)
}
if resp == nil || resp.Body == "" {
return nil, fmt.Errorf("GLEIFSearchFuzzyCompletions: failed to obtain the LEI record for %s", name)
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GLEIFSearchFuzzyCompletions, the error text refers to obtaining an "LEI record", but this function is calling the fuzzy completions endpoint and returns a FuzzyCompletionsResponse. This makes logs/debugging misleading; please update the messages to reference fuzzy completions (and ideally the endpoint/name being queried) rather than an LEI record.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +29
func TestGLEIFGetLEIRecordNilResponseNoPanic(t *testing.T) {
t.Cleanup(func() {
requestWebPage = http.RequestWebPage
})

requestWebPage = func(ctx context.Context, r *http.Request) (*http.Response, error) {
return nil, nil
}

require.NotPanics(t, func() {
record, err := GLEIFGetLEIRecord("ZXTILKJKG63JELOEG630")
require.Error(t, err)
require.Nil(t, record)
})
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nil-response guards were added to GLEIFSearchFuzzyCompletions as well, but there is no deterministic regression test covering the nil-response path for this function (unlike the LEI/direct-parent/direct-children helpers). Please add a TestGLEIFSearchFuzzyCompletionsNilResponseNoPanic-style test that stubs requestWebPage to return (nil, nil) and asserts an error is returned without panicking.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +22
t.Cleanup(func() {
requestWebPage = http.RequestWebPage
})

requestWebPage = func(ctx context.Context, r *http.Request) (*http.Response, error) {
return nil, nil
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests reset requestWebPage to http.RequestWebPage unconditionally. To avoid order-dependence if future tests also stub requestWebPage, it’s safer to capture the prior value at the start of each test and restore that in t.Cleanup (instead of assuming the default).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants