Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f67b95b
cyber challenges page update by krishna chaudhari
kri2tle Aug 31, 2025
b1d2f66
Update xss_attempts.log
kri2tle Aug 31, 2025
1728e36
Add Python Compiler and Enhanced Quiz Integration
kri2tle Sep 14, 2025
867e3ad
conflicts fixed
kri2tle Sep 14, 2025
1a0041d
Merge branch 'main' into main
kri2tle Sep 14, 2025
eb13d00
push
kri2tle Sep 14, 2025
55ed486
Merge branch 'main' of https://github.com/kri2tle/Hardhat-Enterprises…
kri2tle Sep 14, 2025
706d804
Add comprehensive quiz system with leaderboard integration
kri2tle Sep 16, 2025
0345e50
Update and rename 0002_quiz_quizquestion.py to 0001_initial.p
kri2tle Sep 17, 2025
5a60123
Delete home/migrations/0003_userscore.py
kri2tle Sep 17, 2025
3f5af3c
Delete home/migrations/0004_remove_quiz_unique_constraint.py
kri2tle Sep 17, 2025
36da6fe
Merge branch 'main' into main
kri2tle Sep 17, 2025
0b56f67
Merge branch 'main' into main
kri2tle Sep 17, 2025
1708f23
Delete home/migrations/0001_initial.p
kri2tle Sep 17, 2025
ea24b7a
Merge branch 'main' of https://github.com/kri2tle/Hardhat-Enterprises…
kri2tle Sep 17, 2025
566f1d4
Refactor NavBar Tooltip Implementation
kri2tle Sep 19, 2025
bf30cef
Merge branch 'main' of https://github.com/kri2tle/Hardhat-Enterprises…
kri2tle Sep 19, 2025
ca4304c
Consolidate migrations and add login bypass for testing
kri2tle Sep 19, 2025
cc1b59c
Remove temporary login bypass and restore authentication
kri2tle Sep 19, 2025
b66c234
fix: resolve database migration conflicts with IF NOT EXISTS clauses
kri2tle Sep 19, 2025
4240cf9
Merge branch 'main' into main
kri2tle Sep 19, 2025
e89c21c
Security: Fix 30 CodeQL vulnerabilities
kri2tle Sep 19, 2025
647437e
Merge remote changes and resolve conflicts
kri2tle Sep 19, 2025
c8da071
Fix merge conflicts and missing dependencies
kri2tle Sep 19, 2025
82fe5c5
Consolidate database migrations into single initial migration
kri2tle Sep 20, 2025
04000b2
solved issue regarding the multiple migration files
kri2tle Sep 20, 2025
b4e2f74
Fix critical security vulnerabilities identified by CodeQL
kri2tle Sep 20, 2025
aa357f0
Enhanced security fixes and CodeQL configuration
kri2tle Sep 20, 2025
d4c345a
Merge branch 'main' into main
kri2tle Sep 20, 2025
59ef234
Fix CodeQL configuration syntax errors
kri2tle Sep 20, 2025
1c7fe1d
Update documentation for CodeQL configuration fixes
kri2tle Sep 20, 2025
2495c6a
Fix CodeQL queries syntax - use YAML list format
kri2tle Sep 20, 2025
5572ce4
Update documentation with final CodeQL syntax fix details
kri2tle Sep 20, 2025
e93f95d
Fix all critical CodeQL security issues
kri2tle Sep 20, 2025
ce81476
Fix final XSS warning in search suggestions navigation
kri2tle Sep 20, 2025
2283a4a
Enhanced GitHub Actions workflow and addressed CodeQL warnings
kri2tle Sep 20, 2025
c299b7f
Fix CodeQL init action failure with progressive debugging approach
kri2tle Sep 20, 2025
cac8021
Fix CodeQL security alerts and workflow configuration
kri2tle Sep 20, 2025
8ecfb3e
Fix dependency review workflow permissions warning
kri2tle Sep 20, 2025
2d78331
Add top-level permissions to CodeQL workflow
kri2tle Sep 20, 2025
756a75d
Merge branch 'main' into main
kri2tle Sep 21, 2025
77b7035
Removed duplicate @admin.register(Resource) ResourceAdmin class
kri2tle Sep 21, 2025
d70bac7
Merge branch 'main' into main
kri2tle Sep 21, 2025
8f5a48d
Merge branch 'main' into main
kri2tle Sep 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
45 changes: 45 additions & 0 deletions .codeqlignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# CodeQL ignore file - exclude third-party libraries from security scanning

# Django Extensions (third-party)
static/django_extensions/

# DRF-YASG Swagger UI (third-party)
static/drf-yasg/

# Django REST Framework (third-party)
static/rest_framework/

# TinyMCE Editor (third-party)
static/tinymce/

# General vendor directories
static/vendor/
vendor/

# Node modules
node_modules/

# Virtual environments
venv/
env/
.venv/

# Minified files (usually third-party)
**/*.min.js
**/*.min.css
**/*.bundle.js

# Build directories
build/
dist/
.next/

# Database files
*.sqlite3
*.db

# Cache directories
__pycache__/
.cache/
*.pyc
*.pyo
100 changes: 100 additions & 0 deletions .github/CODEQL_WARNINGS_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# CodeQL Warnings Guide

This document explains common CodeQL workflow warnings and how to interpret them.

## ⚠️ Common Warnings (These are NOT failures)

### 1. "Unable to write summary to pull-request"
**Status:** ⚠️ Warning (Not a failure)
**Cause:** Workflow permissions or repository settings
**Impact:** CodeQL analysis still runs, but PR comments may not be posted

**Solutions:**
- βœ… **Already implemented**: Workflow has `pull-requests: write` permission
- βœ… **Already implemented**: Additional permissions added for comprehensive access
- πŸ” **Check**: Repository settings β†’ Actions β†’ General β†’ Workflow permissions
- πŸ” **Check**: If running from a fork, permissions are limited by GitHub security

### 2. "Cannot create diff range extension pack for diff-informed queries"
**Status:** ℹ️ Informational (Not a failure)
**Cause:** Large number of changed files (>300) in pull request
**Impact:** CodeQL performs full analysis instead of optimized diff analysis
**Result:** βœ… **Analysis still completes successfully** - just takes longer

**Why this happens:**
- Diff-based analysis is an optimization for smaller changesets
- When too many files change, CodeQL falls back to full analysis
- This is **by design** and **not an error**

### 3. "Cannot retrieve the full diff because there are too many changed files"
**Status:** ℹ️ Informational (Not a failure)
**Cause:** Same as #2 - large changeset
**Impact:** Same as #2 - full analysis instead of diff analysis
**Result:** βœ… **Analysis still works perfectly**

## βœ… What Our Workflow Does

### **Enhanced Permissions:**
```yaml
permissions:
actions: read
contents: read
security-events: write
pull-requests: write
issues: write
repository-projects: read
statuses: write
```

### **Better Diff Handling:**
- Fetches full git history (`fetch-depth: 0`)
- Checks changeset size and provides informative messages
- Continues analysis regardless of diff optimization availability

### **Error Resilience:**
- Uploads results even with warnings
- Provides clear messaging about what's happening
- Distinguishes between actual failures and informational messages

## 🎯 Expected Behavior

### **Small Pull Requests (<300 files):**
- βœ… Diff-based analysis (faster)
- βœ… All optimizations active
- βœ… PR comments posted

### **Large Pull Requests (>300 files):**
- ⚠️ Warning messages about diff analysis (expected)
- βœ… Full analysis performed (slower but complete)
- βœ… All security issues detected
- βœ… Results uploaded successfully

## πŸ”§ Troubleshooting

### **If PR comments aren't posted:**
1. Check repository Settings β†’ Actions β†’ General
2. Ensure "Read and write permissions" is selected
3. Verify workflow has `pull-requests: write` permission βœ… (already set)

### **If analysis fails completely:**
1. Check for actual error messages (not warnings)
2. Review CodeQL configuration syntax
3. Verify paths in `.github/codeql/codeql-config.yml`

## πŸ“Š Success Indicators

**βœ… CodeQL is working correctly if you see:**
- Security analysis completes
- Results uploaded to GitHub Security tab
- No actual error messages (warnings are OK)
- Security issues detected and reported

**❌ Actual problems would show as:**
- Workflow fails completely
- No results uploaded
- Configuration syntax errors
- Build failures

---

**Summary:** The warnings you're seeing are **normal** and **expected** for large changesets. CodeQL is working correctly and providing comprehensive security analysis.
10 changes: 10 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "CodeQL config"

paths-ignore:
- static/django_extensions
- static/drf-yasg
- static/rest_framework
- static/vendor
- static/tinymce
- venv
- node_modules
60 changes: 31 additions & 29 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
name: "CodeQL Advanced"
name: "CodeQL Security Analysis"

on:
push:
branches: [ "main" ]
branches: [ "main", "master" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "master" ]
schedule:
- cron: '37 1 * * 1'
- cron: '30 2 * * 1'

permissions:
actions: read
contents: read
security-events: write
pull-requests: write

jobs:
analyze:
name: Analyse (${{ matrix.language }})
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
name: Analyze
runs-on: ubuntu-latest
permissions:
security-events: write
packages: read
actions: read
contents: read
security-events: write
pull-requests: write

strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
- language: python
build-mode: none
language: [ 'javascript', 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}

- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml

- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
5 changes: 5 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
permissions:
contents: read
pull-requests: write
actions: read
security-events: read

jobs:
dependency-review:
Expand All @@ -19,4 +21,7 @@ jobs:
uses: actions/dependency-review-action@v4
with:
comment-summary-in-pr: always
fail-on-severity: high
allow-licenses: MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC
continue-on-error: false

110 changes: 110 additions & 0 deletions SECURITY_AUDIT_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Security Audit Report

## Date: September 20, 2025

## Fixed Issues

### 1. Critical: Code Injection Vulnerability (FIXED)
- **File**: `home/views.py` line 3444
- **Issue**: Direct use of `exec()` without proper timeout and isolation
- **Fix**: Implemented cross-platform timeout mechanism using threading and enhanced isolation
- **Status**: βœ… RESOLVED

### 2. Medium: DOM XSS in Search Suggestions (FIXED - ENHANCED)
- **File**: `static/js/search_suggestions.js` line 57
- **Issue**: Potential HTML injection through DOM manipulation
- **Fix Applied**:
- βœ… Enhanced approach using `document.createTextNode()` for ultimate XSS prevention
- βœ… Strict input validation allowing only safe characters
- βœ… URL validation with regex patterns
- βœ… Replaced `textContent` with `createTextNode` for maximum security
- **Status**: βœ… RESOLVED (Enhanced Fix Applied)

## Third-Party Library Warnings (DOCUMENTED)

### 3. jQuery BGIframe Plugin
- **Files**: `static/django_extensions/js/jquery.bgiframe.js`
- **Issues**: Lines 18, 21-24 - Unsafe HTML construction
- **Mitigation**: This is a legacy jQuery plugin. Consider removing if not needed or updating to newer version.
- **Risk Level**: Medium
- **Status**: πŸ“‹ DOCUMENTED

### 4. Swagger UI Bundle
- **Files**: `static/drf-yasg/swagger-ui-dist/swagger-ui-*.js`
- **Issues**: Multiple regex and string escaping issues
- **Mitigation**: These are minified vendor files. Update to latest Swagger UI version when possible.
- **Risk Level**: Medium-High
- **Status**: πŸ“‹ DOCUMENTED

### 5. Django REST Framework Highlight.js
- **File**: `static/rest_framework/docs/js/highlight.pack.js`
- **Issues**: HTML attribute sanitization, overly permissive regex
- **Mitigation**: Update Django REST Framework to latest version
- **Risk Level**: Medium
- **Status**: πŸ“‹ DOCUMENTED

## CodeQL Configuration (NEW)

### 4. CodeQL Configuration and Syntax Fix (IMPLEMENTED)
- **Files**: `.github/codeql/codeql-config.yml`, `.codeqlignore`, `.github/workflows/codeql.yml`
- **Issues Fixed**:
- βœ… Fixed "Cannot deserialize value of type java.lang.String from Array value" error
- βœ… Fixed "(config.originalUserInput.queries || []).map is not a function" error
- βœ… Corrected queries syntax to proper YAML list format with 'uses:' syntax
- βœ… Removed unsupported query-filters that caused deserialization errors
- βœ… Simplified configuration to use only supported CodeQL options
- **Purpose**: Exclude third-party library files from security scanning
- **Benefits**:
- βœ… Focuses security analysis on our own code
- βœ… Eliminates false positives from vendor libraries
- βœ… Improves signal-to-noise ratio in security reports
- βœ… Configures proper GitHub workflow for CodeQL
- βœ… Resolves CodeQL workflow initialization errors
- **Status**: βœ… IMPLEMENTED AND FIXED

## Security Enhancements Implemented

### Code Execution Security
- βœ… Cross-platform timeout mechanism
- βœ… Enhanced AST validation
- βœ… Isolated execution environment
- βœ… Restricted builtins and modules
- βœ… Thread-based execution with timeout
- βœ… Comprehensive error handling

### XSS Prevention
- βœ… HTML sanitization in search suggestions
- βœ… Use of `textContent` instead of `innerHTML`
- βœ… Proper attribute escaping

## Recommendations

1. **Update Dependencies**: Update all third-party libraries to their latest versions
2. **Content Security Policy**: Implement CSP headers to mitigate XSS risks
3. **Regular Audits**: Schedule regular security audits using tools like CodeQL
4. **Remove Unused Libraries**: Remove jQuery BGIframe if not actively used
5. **Version Pinning**: Pin dependency versions and regularly update them

## Security Headers Recommended

```python
# Add to Django settings.py
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_REFERRER_POLICY = 'strict-origin-when-cross-origin'
CSP_DEFAULT_SRC = ("'self'",)
CSP_SCRIPT_SRC = ("'self'", "'unsafe-inline'") # Minimize unsafe-inline usage
CSP_STYLE_SRC = ("'self'", "'unsafe-inline'")
```

## Testing Completed

- βœ… Code execution functionality preserved
- βœ… Search suggestions working correctly
- βœ… No breaking changes to existing features
- βœ… Security measures active and functional

---

**Report Generated**: September 20, 2025
**Next Review**: Recommended within 3 months or after major dependency updates
Loading
Loading