-
Notifications
You must be signed in to change notification settings - Fork 69
fix: skip nil RequestOptions to prevent nil pointer dereferences on option.apply(r)
#578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @esotuvaka , Thank you for submitting this pull request! I appreciate the effort to make the SDK more robust against potential misuse. However, the // Instead of this (which could lead to issues if nil is passed):
{SDK}.Organization.Invitations(ctx, organizationID, nil)
// Just do this:
{SDK}.Organization.Invitations(ctx, organizationID) This aligns with Go's idiomatic handling of optional parameters and avoids the nil pointer dereference risk without additional checks in the code[1]. If there's a specific use case where passing nil is unavoidable or if I'm missing context, could you elaborate? I'd be happy to discuss further or explore alternatives. |
Understood. I see the importance of sticking with idioms, but in this case nil is valid input for this function param, which if given crashes the entire process in the caller of the SDK. We would have to rely on the developer to check that variadic RequestOptions are interfaces that can accept nil as a valid value, and there is no input validation against this. The use case for this is putting an rbac controlled endpoint in front to allow Admin users of multi-tenant applications to add request params, or just general dynamic options for requests where the derivation of the option comes from a pointer to a thing. If in the future list calls support filtering, the onus would be on the caller of the SDK to prevent nil input to these functions. This PR aims to prevent these nil pointer dereferences at the source by avoiding invalid input. tl;dr: SDK as a whole has been really great to work with, I just want to patch this footgun. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #578 +/- ##
==========================================
- Coverage 96.01% 95.97% -0.05%
==========================================
Files 60 60
Lines 12236 12243 +7
==========================================
+ Hits 11749 11750 +1
- Misses 367 371 +4
- Partials 120 122 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Thanks for the explanation, it makes sense, and I agree that this is a good safety check. Skipping The change looks good overall! Could you add a test to cover the Really appreciate the contribution, thanks again! |
Will do! Cheers! |
Funny thing, the test cases were practically already there. I learned something interesting about the language today. I guess implicitly Golang interprets request, err := api.NewRequest(
context.Background(),
testCase.method,
testCase.endpoint,
testCase.payload,
testCase.options...) Which means: api.NewRequest(
context.Background(),
testCase.method,
testCase.endpoint,
testCase.payload,
nil...)
!=
api.NewRequest(
context.Background(),
testCase.method,
testCase.endpoint,
testCase.payload,
nil) Using values, passing |
Hi @esotuvaka, I've updated the test cases to be more focused and cleaner. The original The new tests directly validate the actual bug you're fixing:
This approach is simpler, removes the need for conditional assertions, and tests exactly what the PR fixes. The tests now properly fail on the main branch and pass with your changes. |
Awesome, thank you so much Kunal. Also saw you tidied up my lint errors. With your finishing touches applied I hope this PR can help SDK users! |
Hi @esotuvaka , I overlooked the signed commits. Can you sign the commits? |
Sure. I'm at work currently so don't have access to home PC with the GPG key configured. I'll take a look tonight |
Sure! That would be awesome. Thank you for your contribution. |
3a52e07
to
89b9e62
Compare
…ilOptionsInHelperFunctions
e21865c
to
3407748
Compare
Ah I think I've messed up the history. I'll close this one and try again with a cleaner history and GPG signing from the start. Thankfully this is a small PR |
Hi @esotuvaka, We’re releasing go-auth0 today. Would it be possible for you to create the PR for this feature today so we can get it merged? |
Apologies, I've had an unexpected deadline for work come up. I think I've missed this release cycle, but I'll get this in as soon as possible. Should have more availability to resolve after Wednesday. Thanks for your patience |
No issues, |
🔧 Changes
Prevents API misuse. Perhaps I should've checked the function types closer before hitting this runtime error, but this should eliminate the panic.
[]RequestOption
, skips whenoption == nil
to prevent a runtime nil pointer dereference viaoption.apply(r)
🔬 Testing
Existing test suite can be extended to include passing
nil
into variadicRequestOption
parameters on different management SDK functions, like{SDK}.Organization.Invitations(ctx, organizationID, nil)
📝 Checklist