-
Notifications
You must be signed in to change notification settings - Fork 13
Upload accessibility report to zeuz server #691
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d35517
Changed the accessibility test action to save the report in the zeuz …
Zayadul-huq-afnan 8c39dec
Added endpoint to serve the accessibility test report
Zayadul-huq-afnan 739b4a7
Merge remote-tracking branch 'origin/dev' into upload-accessibility-r…
Zayadul-huq-afnan 28a2834
Potential fix for pull request finding 'CodeQL / Uncontrolled data us…
Zayadul-huq-afnan 2c5eb33
Potential fix for pull request finding 'CodeQL / Uncontrolled data us…
Zayadul-huq-afnan 0c9238d
Potential fix for pull request finding 'CodeQL / Uncontrolled data us…
Zayadul-huq-afnan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """ | ||
| API endpoint for serving accessibility HTML reports from the node's filesystem. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
| import re | ||
| from fastapi import APIRouter, HTTPException | ||
| from fastapi.responses import FileResponse | ||
| from urllib.parse import unquote | ||
|
|
||
| router = APIRouter(prefix="/debug/reports", tags=["debug-reports"]) | ||
| REPORTS_BASE_DIR = Path("reports/accessibility").resolve() | ||
| SAFE_REPORT_FILENAME_RE = re.compile(r"^[A-Za-z0-9._-]+\.html$") | ||
|
|
||
|
|
||
| @router.get("/accessibility") | ||
| def serve_accessibility_report(file_path: str): | ||
|
|
||
| try: | ||
| # Decode URL-encoded path | ||
| print("Serving accessi file") | ||
| decoded_path = unquote(file_path).strip() | ||
|
|
||
| # Accept only a safe filename (no directory components) | ||
| if not decoded_path: | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail="Invalid report path" | ||
| ) | ||
|
|
||
| # Reject any path separators or dot-directory tokens | ||
| if "/" in decoded_path or "\\" in decoded_path or decoded_path in {".", ".."}: | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail="Invalid report path" | ||
| ) | ||
|
|
||
| # Ensure it is a basename and matches allowed characters + .html extension | ||
| if Path(decoded_path).name != decoded_path or not SAFE_REPORT_FILENAME_RE.match(decoded_path): | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail="Invalid report path" | ||
| ) | ||
|
|
||
| # Resolve path under a fixed reports directory to prevent traversal | ||
| html_file = (REPORTS_BASE_DIR / decoded_path).resolve() | ||
Check failureCode scanning / CodeQL Uncontrolled data used in path expression High
This path depends on a
user-provided value Error loading related location Loading |
||
| try: | ||
| html_file.relative_to(REPORTS_BASE_DIR) | ||
| except ValueError: | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail="Invalid report path" | ||
| ) | ||
|
|
||
| # Security check: ensure file exists and is a file (not a directory) | ||
| if not html_file.exists(): | ||
| raise HTTPException( | ||
| status_code=404, | ||
| detail=f"Accessibility report file not found: {file_path}" | ||
| ) | ||
|
|
||
| if not html_file.is_file(): | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| raise HTTPException( | ||
| status_code=400, | ||
| detail=f"Path is not a file: {file_path}" | ||
| ) | ||
|
|
||
| # Verify it's an HTML file | ||
| if html_file.suffix.lower() != ".html": | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail=f"File is not an HTML file: {file_path}" | ||
| ) | ||
|
|
||
| return FileResponse( | ||
| str(html_file), | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| media_type="text/html", | ||
| filename=html_file.name | ||
| ) | ||
|
|
||
| except HTTPException: | ||
| raise | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=f"Failed to retrieve accessibility report: {str(e)}") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.