How to Configure JavaScript Challenges¶
This guide shows you how to set up and customize JavaScript challenges in Peakhour's firewall system to distinguish legitimate browsers from automated tools while maintaining a smooth user experience.
Before you begin: Ensure you have configured basic bot protection and understand firewall rule creation.
Understanding JavaScript Challenges¶
JavaScript challenges validate that visitors are using real browsers rather than automated scripts. The system injects lightweight JavaScript code that performs validation tests only real browsers can complete.
How Challenges Work¶
- Challenge Injection: JavaScript code is inserted into responses
- Browser Validation: Code performs tests that automation tools typically fail
- Token Generation: Successful validation creates authentication tokens
- Access Granted: Valid tokens allow continued site access
- Token Persistence: Challenges remain valid for configured duration
Challenge Types¶
Peakhour implements browser validation challenges that test:
- JavaScript execution capability
- DOM manipulation abilities
- Browser-specific API availability
- Timing-based validation
- Cryptographic verification
Enable JavaScript Challenge System¶
Activate Challenge Infrastructure¶
- Navigate to Security > Bot Protection
- Enable "Inject lightweight JavaScript into the browser to assist with Bot detection"
- Verify the system shows "Challenge System: Active"
Configure Challenge Cookie Keys¶
Select elements that form the challenge tracking key:
- Go to Firewall > Challenge Configuration
- Choose challenge key components:
Available Options:
ip
: Track challenges per IP addresssession_id
: Per-session challenge trackingfingerprint_tls
: TLS fingerprint-based identification
Recommended Combinations:
Test Challenge Activation¶
Verify challenges are working:
- Clear browser cache to remove any existing tokens
- Visit your site from an IP that triggers challenges
- Check developer tools for challenge JavaScript execution
- Verify access after successful challenge completion
Configure Challenge Triggers¶
Rate Limit Challenge Triggers¶
Set up rate limiting that escalates to challenges:
- Navigate to Rules > Rate Limiting
- Create rate limit with challenge action:
API Protection
Login Protection
Firewall Rule Challenge Triggers¶
Create firewall rules that trigger challenges for suspicious patterns:
- Navigate to Rules > Firewall
- Create rules with
challenge
action:
Suspicious User Agents
Missing Browser Headers
Geographic Challenge
Conditional Challenge Rules¶
Create sophisticated rules that challenge based on multiple factors:
Conditional API Access
Time-Based Challenges (using lists for maintenance windows)
Customize Challenge Behavior¶
Configure Challenge Duration¶
Set how long successful challenges remain valid:
- Short Duration (15-60 minutes): High security, more user friction
- Medium Duration (4-12 hours): Balanced security and usability
- Long Duration (24-48 hours): Lower friction, reduced security
Example Configurations:
Configure Challenge Difficulty¶
Adjust challenge complexity based on threat level:
Standard Challenge (recommended for most sites):
- Basic JavaScript execution tests
- Simple DOM manipulation
- Standard timing validation
Enhanced Challenge (high-security environments):
- Multiple validation rounds
- Advanced browser API tests
- Extended timing requirements
- Additional fingerprinting
Set Challenge Retry Logic¶
Configure what happens when challenges fail:
Retry Configuration
Handle Challenge Exceptions¶
Create Allow Lists¶
Bypass challenges for trusted sources:
Trusted IP Ranges
Verified User Agents
API Keys or Tokens
Handle Special Cases¶
Configure exceptions for specific scenarios:
Mobile App Access
Monitoring Services
Progressive Challenge Escalation¶
Implement graduated response based on risk level:
Low Risk - Log Only
Medium Risk - Challenge
High Risk - Block
Monitor Challenge Effectiveness¶
Review Challenge Analytics¶
Monitor key metrics to assess challenge performance:
- Navigate to Analytics > Security Events
-
Review challenge-specific metrics:
-
Challenge Success Rate: Percentage of challenges completed successfully
-
Challenge Volume: Number of challenges triggered daily
-
Failure Patterns: Common reasons for challenge failures
- Geographic Distribution: Challenge activity by location
Target Metrics:
- Success Rate: 60-80% (indicates good balance)
- False Positive Rate: < 5% (legitimate users affected)
- Block Rate: Varies by threat level
Identify Challenge Issues¶
Look for patterns indicating problems:
High Failure Rate (> 80% failures):
- Challenge difficulty too high
- JavaScript compatibility issues
- Legitimate users being affected
Low Challenge Volume (< expected):
- Rules not triggering as intended
- Allow lists too broad
- Challenge thresholds too high
Geographic Anomalies:
- Unexpected challenge patterns in certain regions
- Legitimate traffic being challenged
- Attack patterns from specific countries
Analyze Failed Challenges¶
Investigate challenge failures to improve accuracy:
Common Failure Patterns
Pattern: JavaScript disabled browsers
Solution: Provide alternative validation method
Pattern: Legitimate automation tools
Solution: Add user agent exceptions
Pattern: Slow network connections
Solution: Adjust challenge timeout values
Pattern: Browser compatibility issues
Solution: Update challenge code for compatibility
Optimize Challenge Configuration¶
Fine-Tune Challenge Keys¶
Adjust challenge tracking based on observed patterns:
If seeing challenge bypasses:
- Add
fingerprint_tls
to challenge keys - Consider adding
session_id
for session-specific tracking - Review IP-based challenges for distributed attacks
If seeing high false positives:
- Remove
session_id
from challenge keys - Use IP-only challenges for broader compatibility
- Implement more specific targeting rules
Adjust Challenge Sensitivity¶
Modify rules based on traffic analysis:
Reduce False Positives:
# Before: Too broad
http.user_agent not contains "Mozilla"
# After: More specific
http.user_agent matches ".*(curl|wget).*" and
not http.accept exists
Increase Bot Detection:
# Before: Basic detection
http.user_agent contains "bot"
# After: Comprehensive detection
(http.user_agent matches ".*(bot|crawler|spider).*" or
not http.accept_language exists or
http.user_agent matches ".*python.*") and
not http.user_agent matches ".*(googlebot|bingbot).*"
Implement Adaptive Thresholds¶
Adjust challenge triggers based on traffic patterns:
Low Traffic Periods
High Traffic Periods
Advanced Challenge Configurations¶
Multi-Stage Challenges¶
Implement progressive challenge difficulty:
Stage 1 - Basic Challenge
Stage 2 - Enhanced Challenge (if Stage 1 failed)
Context-Aware Challenges¶
Configure challenges based on request context:
API Endpoint Protection
Admin Area Protection
Integration with Rate Limiting¶
Coordinate challenges with rate limiting for comprehensive protection:
Cascading Protection:
- Rate Limit: Normal traffic allowed
- Challenge: Suspicious traffic challenged
- Block: Malicious traffic blocked
Cascading Protection
Troubleshooting Common Issues¶
Challenge Loop Problems¶
Problem: Users stuck in repeated challenges Solution:
- Check challenge cookie configuration for conflicts
- Verify JavaScript compatibility with site frameworks
- Review session management settings
- Check for multiple overlapping challenge rules
Legitimate Users Challenged¶
Problem: Real users frequently receive challenges Solution:
- Add user agent allow lists for legitimate tools
- Review geographic rules for overly broad restrictions
- Adjust rate limiting thresholds
- Implement IP allow lists for trusted sources
Challenges Not Triggering¶
Problem: Expected challenges not appearing Solution:
- Verify JavaScript injection is enabled
- Check firewall rule priorities and ordering
- Review rule expressions for syntax errors
- Confirm rate limiting thresholds are appropriate
Performance Impact¶
Problem: Challenges affecting site performance Solution:
- Optimize JavaScript challenge code
- Review challenge frequency and duration
- Implement more targeted rules to reduce challenge volume
- Consider CDN optimization for challenge assets
Best Practices¶
Security¶
- Use TLS fingerprinting for enhanced device identification
- Implement progressive challenge escalation
- Regular review and update of challenge rules
- Monitor for challenge bypass attempts
User Experience¶
- Keep challenge duration reasonable for your use case
- Provide clear messaging during challenge process
- Test challenge flow across different browsers and devices
- Implement graceful fallbacks for JavaScript-disabled browsers
Performance¶
- Minimize JavaScript challenge complexity
- Cache challenge assets effectively
- Monitor challenge success rates for optimization
- Use targeted rules to reduce unnecessary challenges
Your JavaScript challenge system is now configured to provide robust protection against automated threats while maintaining accessibility for legitimate users and services.