Skip to content

Commit c2aa2d9

Browse files
authored
Add bot detection commands (#1435)
* fix(go.mod): update go-auth0 dependency to point DXCDT-1069/add_bot_detection branch commit - Updated the go-auth0 dependency from v1.33.0 to v1.33.1-0.20260211120643-ac1cfcb90495. - This change ensures compatibility with the latest features and fixes provided by the go-auth0 library. * feat(attack_protection): add bot detection management commands - Introduced new commands for managing bot detection settings, including: - `bot-detection show`: Displays current bot detection settings. - `bot-detection update`: Updates bot detection settings with user-defined parameters. - Added `GetBotDetection` and `UpdateBotDetection` methods to the AttackProtectionAPI interface for retrieving and updating settings. - Implemented a new `botDetectionView` struct for rendering bot detection settings in the CLI. - Enhanced the attack protection command structure to include bot detection management. * feat(attack_protection): add bot detection test cases - Introduced new test cases for bot detection functionality. - Added tests for both showing and updating bot detection settings. - Ensured that the output contains relevant fields. - These changes enhance the coverage of the attack protection feature. * feat(attack_protection): move attack protection test cases to a dedicated file - Created a new YAML file for integration test cases specifically for attack protection features, including bot detection. - Moved existing test cases related to attack protection from `test-cases.yaml` to `attack-protection-test-cases.yaml` for better organization and clarity. - Each test case verifies the expected output and exit codes for various attack protection commands, ensuring functionality and reliability of the bot detection feature. * feat(attack_protection): add bot detection commands documentation - Updated `auth0_protection.md` to include a link to the new bot detection management commands. - Created `auth0_protection_bot-detection.md` to describe bot detection features and settings. - Added `auth0_protection_bot-detection_show.md` for displaying current bot detection settings. - Added `auth0_protection_bot-detection_update.md` for updating bot detection settings. * feat(management): add v2 management client initialization - Introduced a new function `initializeManagementClientV2` to create a management client using the v2 API. - This function utilizes the `github.com/auth0/go-auth0/v2` package for improved management capabilities. - Updated `go.mod` and `go.sum` to include the v2 dependency. * feat(attack_protection): integrate api-v2 in bot detection management - Added support for v2 management client in the attack protection module. - Added the AttackProtectionBotDetectionAPIV2 interface to use v2 types. - Refactored bot detection show command to utilize new v2 API methods. - Adjusted display functions to handle v2 bot detection response types. - Enhanced the CLI to initialize and use the v2 management client. * feat(attack_protection): add bot detection update command with go-auth0-v2 - Updated the `updateBotDetectionCmdRun` function to utilize the new go-auth0 v2 for bot detection settings. - Introduced a new `stringPtr` utility function to handle string-derived pointer conversions. - Added tests for `stringPtr` to ensure correct behavior with nil and custom string types. - Refactored rendering functions to accommodate changes in the bot detection settings response structure. - Improved user prompts for bot detection configuration options. * chore(go.mod, go.sum): revert go-auth0 version to v1.33.0 - Updated go-auth0 dependency from v1.33.1 to v1.33.0 in go.mod and go.sum * refactor(cli): improve comments and simplify nonInputValueFlags initialization * refactor(cli): simplify bot detection update command logic - Renamed variable `bd` to `current` for clarity in the `updateBotDetectionCmdRun` function. - Removed the `noInputValueFlagSet` function and its associated logic to streamline command behavior. * refactor(bot-detection): update monitoring mode flag naming for consistency - Changed the long form of the monitoring mode flag from `monitoring-mode` to `monitoring-mode-enabled` for clarity and consistency with other command flags. * test(bot-detection): enhance tests to ensure boolean flag remain intact * refactor(cli): rename shouldPromptWhenNoLocalFlagsSet to noLocalFlagSet - Updated the function name from `shouldPromptWhenNoLocalFlagsSet` to `noLocalFlagSet` for clarity and consistency. - Adjusted the logic in `appsSessionTransferUpdateCmd` and `updateBotDetectionCmdRun` to utilize the new function name. - Improved readability by ensuring the function clearly indicates its purpose of checking for local flags.
1 parent 58cef29 commit c2aa2d9

19 files changed

Lines changed: 680 additions & 87 deletions

docs/auth0_protection.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Auth0 can detect attacks and stop malicious attempts to access your application
88

99
## Commands
1010

11+
- [auth0 protection bot-detection](auth0_protection_bot-detection.md) - Manage bot detection settings
1112
- [auth0 protection breached-password-detection](auth0_protection_breached-password-detection.md) - Manage breached password detection settings
1213
- [auth0 protection brute-force-protection](auth0_protection_brute-force-protection.md) - Manage brute force protection settings
1314
- [auth0 protection suspicious-ip-throttling](auth0_protection_suspicious-ip-throttling.md) - Manage suspicious ip throttling settings
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: default
3+
has_toc: false
4+
has_children: true
5+
---
6+
# auth0 protection bot-detection
7+
8+
Bot detection protects your applications from automated attacks by detecting and blocking bot traffic. Auth0 can challenge suspicious requests with CAPTCHA or block them entirely. Configure detection sensitivity, CAPTCHA policies for different authentication flows, and allowlists for trusted IP addresses.
9+
10+
## Commands
11+
12+
- [auth0 protection bot-detection show](auth0_protection_bot-detection_show.md) - Show bot detection settings
13+
- [auth0 protection bot-detection update](auth0_protection_bot-detection_update.md) - Update bot detection settings
14+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
layout: default
3+
parent: auth0 protection bot-detection
4+
has_toc: false
5+
---
6+
# auth0 protection bot-detection show
7+
8+
Display the current bot detection settings.
9+
10+
## Usage
11+
```
12+
auth0 protection bot-detection show [flags]
13+
```
14+
15+
## Examples
16+
17+
```
18+
auth0 protection bot-detection show
19+
auth0 ap bd show --json
20+
auth0 ap bd show --json-compact
21+
```
22+
23+
24+
## Flags
25+
26+
```
27+
--json Output in json format.
28+
--json-compact Output in compact json format.
29+
```
30+
31+
32+
## Inherited Flags
33+
34+
```
35+
--debug Enable debug mode.
36+
--no-color Disable colors.
37+
--no-input Disable interactivity.
38+
--tenant string Specific tenant to use.
39+
```
40+
41+
42+
## Related Commands
43+
44+
- [auth0 protection bot-detection show](auth0_protection_bot-detection_show.md) - Show bot detection settings
45+
- [auth0 protection bot-detection update](auth0_protection_bot-detection_update.md) - Update bot detection settings
46+
47+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
layout: default
3+
parent: auth0 protection bot-detection
4+
has_toc: false
5+
---
6+
# auth0 protection bot-detection update
7+
8+
Update the bot detection settings.
9+
10+
## Usage
11+
```
12+
auth0 protection bot-detection update [flags]
13+
```
14+
15+
## Examples
16+
17+
```
18+
auth0 protection bot-detection update
19+
auth0 ap bd update --bot-detection-level medium --json-compact
20+
auth0 ap bd update --bot-detection-level low --challenge-password-policy never
21+
auth0 ap bd update --monitoring-mode-enabled=true --allowlist "198.51.100.42,10.0.0.0/24"
22+
auth0 ap bd update -l high -a "198.51.100.42" -m=false --json
23+
```
24+
25+
26+
## Flags
27+
28+
```
29+
-a, --allowlist strings List of comma-separated trusted IP addresses that will not have bot detection enforced against them. Supports IPv4, IPv6 and CIDR notations.
30+
-l, --bot-detection-level string The level of bot detection sensitivity. Possible values: low, medium, high.
31+
--challenge-password-policy string Determines how often to challenge users with a CAPTCHA for password-based login. Possible values: never, when_risky, always.
32+
--challenge-password-reset-policy string Determines how often to challenge users with a CAPTCHA for password reset. Possible values: never, when_risky, always.
33+
--challenge-passwordless-policy string Determines how often to challenge users with a CAPTCHA for passwordless login. Possible values: never, when_risky, always.
34+
--json Output in json format.
35+
--json-compact Output in compact json format.
36+
-m, --monitoring-mode-enabled Enable (or disable) monitoring mode. When enabled, logs but does not block.
37+
```
38+
39+
40+
## Inherited Flags
41+
42+
```
43+
--debug Enable debug mode.
44+
--no-color Disable colors.
45+
--no-input Disable interactivity.
46+
--tenant string Specific tenant to use.
47+
```
48+
49+
50+
## Related Commands
51+
52+
- [auth0 protection bot-detection show](auth0_protection_bot-detection_show.md) - Show bot detection settings
53+
- [auth0 protection bot-detection update](auth0_protection_bot-detection_update.md) - Update bot detection settings
54+
55+

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/PuerkitoBio/rehttp v1.4.0
88
github.com/atotto/clipboard v0.1.4
99
github.com/auth0/go-auth0 v1.34.0
10+
github.com/auth0/go-auth0/v2 v2.5.0
1011
github.com/briandowns/spinner v1.23.2
1112
github.com/charmbracelet/glamour v0.10.0
1213
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
2222
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
2323
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
2424
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
25+
github.com/auth0/go-auth0/v2 v2.5.0 h1:IBfiYGsqFwOu4hsxV1JDtB6+ayRinybUIUCU/fRBE8Y=
26+
github.com/auth0/go-auth0/v2 v2.5.0/go.mod h1:XVRck9fw1EIw1z4guYcbKFGmElnexb+xOvQ/0U1hHd0=
2527
github.com/auth0/go-auth0 v1.34.0 h1:5rtel4yYbYp+NYlVf3ryxSRaDHWxJubtVc+cqdLMa7o=
2628
github.com/auth0/go-auth0 v1.34.0/go.mod h1:32sQB1uAn+99fJo6N819EniKq8h785p0ag0lMWhiTaE=
2729
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48=

internal/auth0/attack_protection.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55

66
"github.com/auth0/go-auth0/management"
7+
managementv2 "github.com/auth0/go-auth0/v2/management"
8+
"github.com/auth0/go-auth0/v2/management/option"
79
)
810

911
type AttackProtectionAPI interface {
@@ -64,3 +66,19 @@ type AttackProtectionAPI interface {
6466
opts ...management.RequestOption,
6567
) (err error)
6668
}
69+
70+
type AttackProtectionBotDetectionAPIV2 interface {
71+
// Get the Bot Detection configuration of tenant.
72+
//
73+
// Required scope: `read:attack_protection`
74+
//
75+
// See: https://auth0.com/docs/api/management/v2#!/attack-protection/get-bot-detection
76+
Get(ctx context.Context, opts ...option.RequestOption) (*managementv2.GetBotDetectionSettingsResponseContent, error)
77+
78+
// Update the Bot Detection configuration of tenant.
79+
//
80+
// Required scope: `update:attack_protection`
81+
//
82+
// See: https://auth0.com/docs/api/management/v2#!/attack-protection/patch-bot-detection
83+
Update(ctx context.Context, request *managementv2.UpdateBotDetectionSettingsRequestContent, opts ...option.RequestOption) (*managementv2.UpdateBotDetectionSettingsResponseContent, error)
84+
}

internal/auth0/auth0.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package auth0
33
import (
44
"github.com/auth0/go-auth0"
55
"github.com/auth0/go-auth0/management"
6+
managementv2 "github.com/auth0/go-auth0/v2/management/client"
67
)
78

89
// API mimics `management.Management`s general interface, except it refers to
@@ -76,6 +77,16 @@ func NewAPI(m *management.Management) *API {
7677
}
7778
}
7879

80+
type APIV2 struct {
81+
AttackProtectionBotDetection AttackProtectionBotDetectionAPIV2
82+
}
83+
84+
func NewAPIV2(m *managementv2.Management) *APIV2 {
85+
return &APIV2{
86+
AttackProtectionBotDetection: m.AttackProtection.BotDetection,
87+
}
88+
}
89+
7990
// Alias all the helper methods so we can keep just typing `auth0.Bool` and the
8091
// compiler can autocomplete our internal package.
8192
var (

internal/cli/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ func appsSessionTransferUpdateCmd(cli *cli) *cobra.Command {
11751175
}
11761176

11771177
// Set the flag if it was supplied or entered by the prompt.
1178-
if appSTCanCreateToken.IsSet(cmd) || shouldPromptWhenNoLocalFlagsSet(cmd) {
1178+
if appSTCanCreateToken.IsSet(cmd) || noLocalFlagSet(cmd) {
11791179
st.CanCreateSessionTransferToken = &inputs.CanCreateToken
11801180
}
11811181

internal/cli/attack_protection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func attackProtectionCmd(cli *cli) *cobra.Command {
1919
cmd.AddCommand(breachedPasswordDetectionCmd(cli))
2020
cmd.AddCommand(bruteForceProtectionCmd(cli))
2121
cmd.AddCommand(suspiciousIPThrottlingCmd(cli))
22+
cmd.AddCommand(botDetectionCmd(cli))
2223

2324
return cmd
2425
}

0 commit comments

Comments
 (0)