Skip to content

Conversation

@sixcolors
Copy link
Member

This PR updates the UUID function in common.go to panic instead of returning a default UUID when initialization fails. The changes include adding proper error handling for seeding the UUID generator and counter initialization.

Copilot AI review requested due to automatic review settings December 6, 2025 16:36
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sixcolors, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the UUID generation mechanism by implementing a fail-fast approach during its initialization. Instead of silently failing or providing a default, potentially invalid, UUID, the system will now panic if critical steps like seeding the random number generator or initializing the counter encounter errors. This ensures that any issues with UUID setup are immediately apparent, preventing the propagation of invalid UUIDs throughout the application.

Highlights

  • Error Handling: The UUID generation function now panics instead of silently failing or returning a default UUID when initialization errors occur.
  • UUID Seeding: Proper error handling has been introduced for seeding the UUID generator using crypto/rand, causing a panic on failure.
  • Counter Initialization: A check for proper uuidCounter initialization now results in a panic if the counter is not set up correctly, replacing the previous behavior of returning a default UUID string.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the UUID function to panic on initialization errors, which is a good improvement over returning a default UUID. The change to panic when rand.Read fails is correct. However, I've found a critical issue with the new check for the uuidCounter value. It can cause a panic even on successful initialization, albeit in a very rare case. My review includes a comment with a detailed explanation and a suggestion for a fix by removing the problematic check.

Copy link

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

This PR changes the UUID function's error handling strategy from graceful degradation (returning a default UUID) to fail-fast behavior (panicking on initialization errors). This is a significant API change that makes initialization failures immediately visible rather than silently continuing with fallback values.

Key changes:

  • Replaces silent return on rand.Read failure with a descriptive panic message
  • Replaces fallback UUID return with a panic when counter validation fails
  • Adds fmt import to support formatted panic messages

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

@gaby
Copy link
Member

gaby commented Dec 6, 2025

We should return an error, not panic(). Let the caller handle the error and determine the fallback themselves.

@kalafut
Copy link

kalafut commented Dec 9, 2025

Why is this needed? I believe crypto/rand already panics and never returns a non-nil error? (ref: golang/go#66821 & https://cs.opensource.google/go/go/+/refs/tags/go1.25.5:src/crypto/rand/rand.go;l=80

@sixcolors
Copy link
Member Author

sixcolors commented Dec 9, 2025

Why is this needed? I believe crypto/rand already panics and never returns a non-nil error? (ref: golang/go#66821 & https://cs.opensource.google/go/go/+/refs/tags/go1.25.5:src/crypto/rand/rand.go;l=80

@kalafut thanks for pointing this out. You are correct thatcrypto/rand guarantees panic-on-failure beginning in Go 1.24. However, note target branch is v1.

@sixcolors
Copy link
Member Author

Even the master branch of github.com/gofiber/utils/v2 explicitly sets go 1.23.0 in its go.mod

@sixcolors
Copy link
Member Author

We should return an error, not panic(). Let the caller handle the error and determine the fallback themselves.

This is a backport of the security advisory change for utils v1: GHSA‑m98w‑cqp3‑qcqr.

We cannot return an error without changing the function signature, which guarantees a string return. Since UUID() is used for security-critical identifiers (tokens, session IDs, etc.), a failure in crypto/rand must be fatal — returning a zero or predictable UUID would be a critical vulnerability. The Go team’s guidance is the same: RNG failures are unrecoverable and should terminate execution.

The panics here are intentional and correct. While crypto/rand failures pre‑Go 1.24 are extremely rare on modern hosts, the real issue was that utils previously ignored failures and returned the all-zero UUID. Failing fast ensures the process exits so the orchestrator (systemd, Kubernetes, Nomad, Docker Swarm, etc.) can restart or reschedule the service. If the host’s CSPRNG is genuinely broken, the service will crash again — exactly what we want, because it signals an unhealthy node and prevents insecure behaviour.

@ReneWerner87 ReneWerner87 merged commit b986fcc into v1 Dec 10, 2025
24 checks passed
@ReneWerner87 ReneWerner87 deleted the feat/cherry-pick-6c6cf04 branch December 10, 2025 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants