-
Notifications
You must be signed in to change notification settings - Fork 1
Add NewUserProfileController #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| package org.example; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.ResponseBody; | ||
| import org.springframework.web.util.HtmlUtils; | ||
|
|
||
| @Controller | ||
| @RequestMapping("/new") | ||
| public class NewUserProfileController { | ||
|
|
||
| // Display user profile with custom message | ||
| @GetMapping("/profile/display") | ||
| @ResponseBody | ||
| public String displayUserProfile( | ||
| @RequestParam(defaultValue = "Welcome") String message) { | ||
| // Direct output without escaping | ||
| return "<html><body><h1>Profile Message: " + message + "</h1></body></html>"; | ||
| } | ||
|
|
||
| // Display user profile with escaped message | ||
| @GetMapping("/profile/secureDisplay") | ||
| @ResponseBody | ||
| public String displaySecureUserProfile( | ||
| @RequestParam(defaultValue = "Welcome") String message) { | ||
| // Properly escaped output | ||
| return "<html><body><h1>Profile Message: " + | ||
| HtmlUtils.htmlEscape(message) + "</h1></body></html>"; | ||
| } | ||
|
|
||
| // Display user status with local variable assignment | ||
| @GetMapping("/profile/status") | ||
| @ResponseBody | ||
| public String displayUserStatus( | ||
| @RequestParam(defaultValue = "Active") String message) { | ||
| // Assign to local variable | ||
| String htmlContent = "<html><body><h1>User Status: " + | ||
| message + "</h1></body></html>"; | ||
| return htmlContent; | ||
Check failureCode scanning / Seqra Potential cross-site scripting (XSS) Error
Potential XSS: writing user input directly to a web page.
|
||
| } | ||
|
|
||
| // Display escaped user status with local variable assignment | ||
| @GetMapping("/profile/secureStatus") | ||
| @ResponseBody | ||
| public String displaySecureUserStatus( | ||
| @RequestParam(defaultValue = "Active") String message) { | ||
| // Assign to local variable | ||
| String htmlContent = "<html><body><h1>User Status: " + | ||
| HtmlUtils.htmlEscape(message) + "</h1></body></html>"; | ||
| return htmlContent; | ||
| } | ||
|
|
||
| // Generate user dashboard with escaped greeting | ||
| @GetMapping("/dashboard/greeting") | ||
| @ResponseBody | ||
| public String generateDashboard( | ||
| @RequestParam(defaultValue = "Welcome") String greeting) { | ||
| String htmlContent = buildDashboardContent(greeting); | ||
| return htmlContent; | ||
Check failureCode scanning / Seqra Potential cross-site scripting (XSS) Error
Potential XSS: writing user input directly to a web page.
|
||
| } | ||
|
|
||
| private static String buildDashboardContent(String greeting) { | ||
| // Generate dashboard HTML content | ||
| return "<html><body><h1>Dashboard: " + greeting + "</h1></body></html>"; | ||
| } | ||
|
|
||
| // Generate user dashboard with custom greeting | ||
| @GetMapping("/dashboard/secureGreeting") | ||
| @ResponseBody | ||
| public String generateSecureDashboard( | ||
| @RequestParam(defaultValue = "Welcome") String greeting) { | ||
| String htmlContent = buildSecureDashboardContent(greeting); | ||
| return htmlContent; | ||
| } | ||
|
|
||
| private static String buildSecureDashboardContent(String greeting) { | ||
| // Generate dashboard HTML content with escaped greeting | ||
| return "<html><body><h1>Dashboard: " + | ||
| HtmlUtils.htmlEscape(greeting) + "</h1></body></html>"; | ||
| } | ||
|
|
||
| // Generate message template | ||
| @GetMapping("/notifications/template") | ||
| @ResponseBody | ||
| public String generateTemplate( | ||
| @RequestParam(defaultValue = "New Message") String content) { | ||
| Profile.MessageTemplate template = new Profile.MessageTemplate(content); | ||
| // Return nested content | ||
| return template.body.content.text; | ||
Check failureCode scanning / Seqra Potential cross-site scripting (XSS) Error
Potential XSS: writing user input directly to a web page.
|
||
| } | ||
|
|
||
| // Generate message template | ||
| @GetMapping("/notifications/secureTemplate") | ||
| @ResponseBody | ||
| public String generateSecureTemplate( | ||
| @RequestParam(defaultValue = "New Message") String content) { | ||
| Profile.MessageTemplate template = new Profile.MessageTemplate(content); | ||
| // Return nested escaped content | ||
| return template.body.content.secureText; | ||
| } | ||
|
|
||
| // Generate user notification with complex data structure | ||
| @GetMapping("/notifications/generate") | ||
| @ResponseBody | ||
| public String generateNotification( | ||
| @RequestParam(defaultValue = "New Message") String content) { | ||
| // Create user profile with nested message structure using constructors | ||
| Profile.UserProfile profile = new Profile.UserProfile(content); | ||
|
|
||
| // Return nested content | ||
| return profile.settings.config.template.body.content.text; | ||
Check failureCode scanning / Seqra Potential cross-site scripting (XSS) Error
Potential XSS: writing user input directly to a web page.
|
||
| } | ||
|
|
||
| // Generate user notification with complex data structure | ||
| @GetMapping("/notifications/secureGenerate") | ||
| @ResponseBody | ||
| public String generateSecureNotification( | ||
| @RequestParam(defaultValue = "New Message") String content) { | ||
| // Create user profile with nested message structure using constructors | ||
| Profile.UserProfile profile = new Profile.UserProfile(content); | ||
|
|
||
| // Return nested content | ||
| return profile.settings.config.template.body.content.secureText; | ||
| } | ||
|
|
||
| // Display custom message | ||
| @GetMapping("/message/display") | ||
| @ResponseBody | ||
| public String displayMessage( | ||
| @RequestParam(defaultValue = "Welcome") String message) { | ||
| // Construct a page using a chain of builders | ||
| String page = new HtmlPageBuilder().message(message).buildPage(); | ||
|
|
||
| return page; | ||
Check failureCode scanning / Seqra Potential cross-site scripting (XSS) Error
Potential XSS: writing user input directly to a web page.
|
||
| } | ||
|
|
||
| // Display custom message | ||
| @GetMapping("/message/secureDisplay") | ||
| @ResponseBody | ||
| public String displaySecureMessage( | ||
| @RequestParam(defaultValue = "Welcome") String message) { | ||
| // Construct a page using a chain of builders | ||
| String page = new HtmlPageBuilder().message(message).escape().buildPage(); | ||
|
|
||
| return page; | ||
| } | ||
|
|
||
| // Display formatted message | ||
| @GetMapping("/message/format") | ||
| @ResponseBody | ||
| public String formatMessage( | ||
| @RequestParam(defaultValue = "Welcome") String message) { | ||
| // Construct a page using a formatter as a parameter for a chain of builders | ||
| String page = new HtmlPageBuilder().message(message) | ||
| .format(new DefaultFormatter()).buildPage(); | ||
|
|
||
| return page; | ||
Check failureCode scanning / Seqra Potential cross-site scripting (XSS) Error
Potential XSS: writing user input directly to a web page.
|
||
| } | ||
|
|
||
| // Display escaped message | ||
| @GetMapping("/message/escape") | ||
| @ResponseBody | ||
| public String escapeMessage( | ||
| @RequestParam(defaultValue = "Welcome") String message) { | ||
| // Construct a page using a formatter as a parameter for a chain of builders | ||
| String page = new HtmlPageBuilder().message(message) | ||
| .format(new EscapeFormatter()).buildPage(); | ||
|
|
||
| return page; | ||
Check failureCode scanning / Seqra Potential cross-site scripting (XSS) Error
Potential XSS: writing user input directly to a web page.
|
||
| } | ||
| } | ||
Check failure
Code scanning / Seqra
Potential cross-site scripting (XSS) Error