-
Notifications
You must be signed in to change notification settings - Fork 0
chore: enhance AuthGuardFilter and JSP files for improved static asse… #73
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
Conversation
…t handling and layout consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the application's routing, authentication filtering, and styling consistency. The primary changes include introducing a welcome page mechanism via index.jsp, updating the HomeServlet to handle only the /home route, extending the AuthGuardFilter to explicitly whitelist static assets and public pages, and ensuring consistent inclusion of the layout.css stylesheet across JSP views.
Key Changes:
- Added explicit static asset and public route whitelisting in
AuthGuardFilterto prevent authentication checks on CSS, images, and public pages - Introduced
index.jspas a welcome file that forwards to/home, while removing the root path mapping fromHomeServlet - Added
layout.cssto several JSP pages (home, challenges list/detail) and cleaned up redundant HTML boilerplate in header and drill pages
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/webapp/index.jsp |
New welcome file that forwards root requests to /home |
src/main/webapp/WEB-INF/jsp/home.jsp |
Added layout.css stylesheet and removed redundant meta tags |
src/main/webapp/WEB-INF/jsp/header.jsp |
Removed standalone HTML boilerplate and improved code formatting |
src/main/webapp/WEB-INF/jsp/drill/solve.jsp |
Removed comment about explicit meta tags |
src/main/webapp/WEB-INF/jsp/challenges/list.jsp |
Added layout.css stylesheet for consistent layout |
src/main/webapp/WEB-INF/jsp/challenges/detail.jsp |
Added layout.css stylesheet for consistent layout |
src/main/java/me/nickhanson/codeforge/web/HomeServlet.java |
Removed root path (/) from URL patterns, keeping only /home |
src/main/java/me/nickhanson/codeforge/web/AuthGuardFilter.java |
Added static asset and public page whitelisting with path and extension checks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return; | ||
| } | ||
|
|
||
| // 2) Allow your public pages (home/about/login/error) |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 63 has inconsistent indentation. It should be aligned with the surrounding code at the same indentation level as the if statement below it, rather than being flush with the left margin.
| // 2) Allow your public pages (home/about/login/error) | |
| // 2) Allow your public pages (home/about/login/error) |
| if (path.startsWith("/css/") | ||
| || path.startsWith("/images/") | ||
| || path.startsWith("/apidocs/") | ||
| || path.equals("/favicon.ico") | ||
| || path.startsWith("/favicon") | ||
| || path.endsWith(".css") | ||
| || path.endsWith(".js") | ||
| || path.endsWith(".png") | ||
| || path.endsWith(".jpg") | ||
| || path.endsWith(".jpeg") | ||
| || path.endsWith(".gif") | ||
| || path.endsWith(".svg") | ||
| || path.endsWith(".webp")) { |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static asset filtering has redundant checks. Lines 46-50 check for paths starting with "/css/", "/images/", etc., while lines 51-58 check for file extensions like ".css", ".js", ".png", etc. A file like "/css/styles.css" would be allowed by line 46 before reaching the extension check on line 51. Similarly, a CSS file served from a non-standard location (e.g., "/static/app.css") would be allowed by the ".css" extension check on line 51, even though "/static/" isn't in the path prefix list. Consider whether both approaches are needed or if one method would be more maintainable and clearer in intent.
| || path.startsWith("/images/") | ||
| || path.startsWith("/apidocs/") | ||
| || path.equals("/favicon.ico") | ||
| || path.startsWith("/favicon") |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path "/favicon" (line 50) is redundant since the check on line 49 already covers "/favicon.ico" with an exact match, and any path starting with "/favicon" would include "/favicon.ico" as well. The startsWith check for "/favicon" would also match paths like "/favicon.png" or "/favicons/", which may be the intended behavior, but if "/favicon.ico" is the only favicon path that needs to be allowed, line 50 should be removed to avoid confusion.
| || path.startsWith("/favicon") |
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <c:import url="/WEB-INF/jsp/head-meta.jsp" /> | ||
| <link rel="stylesheet" href="${pageContext.request.contextPath}/css/layout.css" /> |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The layout.css stylesheet has been added to home.jsp and the challenges pages (list.jsp, detail.jsp), but not to drill pages (queue.jsp, solve.jsp) or the about.jsp page, which also use the same header component and page structure. This inconsistency could lead to different styling across pages that should have a consistent layout. Consider adding layout.css to all pages that use the header component for consistency.
| String uri = req.getRequestURI(); | ||
| String path = uri.substring(contextPath.length()); |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new variable 'uri' is introduced on line 39 but it's only used once to derive 'path' on line 40. This adds an unnecessary intermediate variable. Consider removing the 'uri' variable and keeping the original single-line assignment: String path = req.getRequestURI().substring(contextPath.length());
| String uri = req.getRequestURI(); | |
| String path = uri.substring(contextPath.length()); | |
| String path = req.getRequestURI().substring(contextPath.length()); |
This pull request improves static asset handling, public route access, and page styling across the application. The most significant changes are the addition of static asset and public page whitelisting in the authentication filter, updates to servlet URL mappings, and consistent inclusion of layout stylesheets in JSP files.
Authentication and Routing Improvements:
AuthGuardFilternow explicitly allows requests for static assets (such as CSS, JS, images) and public pages (home, about, login, error) to bypass authentication, improving access for unauthenticated users and preventing unnecessary filtering of these resources.HomeServletmapping is updated to only respond to/home, removing the root path (/) from its URL patterns.Styling and Layout Consistency:
layout.cssstylesheet to several JSP views (home.jsp,challenges/list.jsp,challenges/detail.jsp) to ensure consistent layout styling across pages. [1] [2] [3]header.jspanddrill/solve.jsp, relying instead on the sharedhead-meta.jspfor meta information and improving maintainability. [1] [2]header.jspfor better readability and consistency.Other Minor Changes:
HttpSessionimport fromAuthGuardFilter.java.