Skip to content
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

feat: HCaptcha Middleware #1071

Merged
merged 16 commits into from
Apr 24, 2024
Merged

feat: HCaptcha Middleware #1071

merged 16 commits into from
Apr 24, 2024

Conversation

bndrmrtn
Copy link
Contributor

@bndrmrtn bndrmrtn commented Apr 9, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced security by introducing HCaptcha middleware to verify tokens and prevent robot submissions in Go applications.
    • Added a GitHub Actions workflow to automate testing of the HCaptcha functionality.
  • Documentation

    • Updated the main README and provided detailed documentation for the HCaptcha middleware.
  • Tests

    • Implemented tests to validate the functionality of the HCaptcha middleware integration.
  • Chores

    • Configured release drafter settings to manage HCaptcha releases effectively.

@bndrmrtn bndrmrtn requested a review from a team as a code owner April 9, 2024 15:49
@bndrmrtn bndrmrtn requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team April 9, 2024 15:49
Copy link
Contributor

coderabbitai bot commented Apr 9, 2024

Walkthrough

The recent changes introduce a robust hcaptcha middleware for Go applications to combat bot intrusions effectively. This middleware integrates seamlessly with the Fiber web framework, enhancing security against automated attacks. Additionally, the updates include automated testing with GitHub Actions, improved dependency management through Dependabot, and streamlined release processes with Release Drafter.

Changes

File Path Change Summary
hcaptcha/config.go Introduced Config struct for HCaptcha middleware configuration and token handling.
hcaptcha/hcaptcha.go Implemented middleware functions for HCaptcha UUID verification.
hcaptcha/.../hcaptcha_test.go Added tests to validate the functionality of the HCaptcha middleware within the Fiber framework.
README.md Added information about the HCaptcha middleware to the main repository README.
.github/.../test-hcaptcha.yml Configured GitHub Actions workflow to run tests for HCaptcha-related changes.
.github/dependabot.yml Set up Dependabot to manage daily updates for Go modules within the hcaptcha directory.
.github/.../release-drafter-hcaptcha.yml Configured Release Drafter to handle HCaptcha-related releases.

🐰✨🌟
In fields of code where bots dare to tread,
A guardian rises, its vigilance spread.
With tokens and keys, it stands at the gate,
Ensuring no robot can seal its own fate.
Cheers to the shield—our new hcaptcha mate!
🌟✨🐰


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Comment on lines +33 to +34
res, err := app.Test(req, -1)
defer res.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure defer res.Body.Close() is called after checking for an error from app.Test(req, -1) to avoid potential nil pointer dereference.

- defer res.Body.Close()
  res, err := app.Test(req, -1)
+ if err != nil {
+     t.Fatal(err)
+ }
+ defer res.Body.Close()

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
res, err := app.Test(req, -1)
defer res.Body.Close()
res, err := app.Test(req, -1)
if err != nil {
t.Fatal(err)
}
defer res.Body.Close()

req.Header.SetMethod("POST")
req.Header.SetContentType("application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Set("Accept", "application/json")
req.SetRequestURI(c.Host())
Copy link
Contributor

Choose a reason for hiding this comment

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

Set the request URI to h.SiteVerifyURL instead of c.Host() for the HCaptcha API call.

- req.SetRequestURI(c.Host())
+ req.SetRequestURI(h.SiteVerifyURL)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
req.SetRequestURI(c.Host())
req.SetRequestURI(h.SiteVerifyURL)

@ReneWerner87
Copy link
Member

ReneWerner87 commented Apr 9, 2024

  • add this new middleware in the root readme
  • add workflows for this new middleware(dependabot, test, release-drafter ... )
  • add readme for the middleware itself

@gaby gaby changed the title initial commit feat: HCaptcha Middleware Apr 10, 2024
@bndrmrtn
Copy link
Contributor Author

  • add this new middleware in the root readme

    • add workflows for this new middleware(dependabot, test, release-drafter ... )

    • add readme for the middleware itself

I added it to the root README and I created a README file for it, I tried to enable dependabot, but I don't know how to excatly enable workflows for this pull request. I never did it before, that's new for me ://

@gaby
Copy link
Member

gaby commented Apr 10, 2024

@bndrmrtn Copy one of the test workflows for the other contrib middlewares, and adapt it to this one.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

.github/workflows/test-hcaptcha.yml Show resolved Hide resolved
@bndrmrtn
Copy link
Contributor Author

I think I did it, right? 🤔

@ReneWerner87
Copy link
Member

will check it tomorrow

Copy link
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

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

  • add release drafter workflow and config
  • add section to the dependabot.yml

README.md Outdated Show resolved Hide resolved
@ReneWerner87
Copy link
Member

pls add a section like this

- package-ecosystem: "gomod"
directory: "/loadshed" # Location of package manifests
labels:
- "🤖 Dependencies"
schedule:
interval: "daily"

and copy the release drafter yaml´s

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

README.md Outdated Show resolved Hide resolved
@ReneWerner87
Copy link
Member

@bndrmrtn pls don't create useless pull requests
Screenshot_2024-04-18-19-29-02-30_40deb401b9ffe8e1df2f1cc5ba480b12

@bndrmrtn
Copy link
Contributor Author

@bndrmrtn pls don't create useless pull requests
Screenshot_2024-04-18-19-29-02-30_40deb401b9ffe8e1df2f1cc5ba480b12

yeah, really sorry 😅

@ReneWerner87 ReneWerner87 added ✏️ Feature New feature or request and removed ♻ Wait for Response labels Apr 19, 2024
@ReneWerner87
Copy link
Member

  • add release drafter workflow and config
  • add section to the dependabot.yml

fixed with f5b94a8

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

hcaptcha/README.md Outdated Show resolved Hide resolved
hcaptcha/README.md Outdated Show resolved Hide resolved
hcaptcha/README.md Show resolved Hide resolved
hcaptcha/README.md Outdated Show resolved Hide resolved
@ReneWerner87
Copy link
Member

@gaby @sixcolors @efectn can you check

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

hcaptcha/README.md Show resolved Hide resolved
hcaptcha/README.md Show resolved Hide resolved
hcaptcha/README.md Show resolved Hide resolved
hcaptcha/README.md Show resolved Hide resolved
hcaptcha/README.md Show resolved Hide resolved
@ReneWerner87 ReneWerner87 merged commit a07a32f into gofiber:main Apr 24, 2024
57 checks passed
@ReneWerner87
Copy link
Member

@bndrmrtn
Copy link
Contributor Author

Thanks! 🤩
Also I really appriciate your help, cuz I'm new to contributing code, that was my first. It feels great that my code is merged into my favourite framework. 😁
I hope it will help some devs integrating with this captcha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants