-
Notifications
You must be signed in to change notification settings - Fork 2
Add SSTI, stored XSS, and SSRF vulnerability modules with Kotlin support #2
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
Open
misonijnik
wants to merge
1
commit into
demo/base
Choose a base branch
from
demo/spring
base: demo/base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
84 changes: 84 additions & 0 deletions
84
src/main/java/org/seqra/spring/content/CampaignController.java
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 @@ | ||
| package org.seqra.spring.content; | ||
|
|
||
| import freemarker.template.TemplateException; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Controller for campaign and notification template rendering. | ||
| */ | ||
| @RestController | ||
| @RequestMapping("/api/campaigns") | ||
| public class CampaignController { | ||
|
|
||
| private final MarketingTemplateService marketingService; | ||
| private final NotificationTemplateService notificationService; | ||
| private final TemplateRenderingService templateService; | ||
|
|
||
| public CampaignController(MarketingTemplateService marketingService, | ||
| NotificationTemplateService notificationService, | ||
| TemplateRenderingService templateService) { | ||
| this.marketingService = marketingService; | ||
| this.notificationService = notificationService; | ||
| this.templateService = templateService; | ||
| } | ||
|
|
||
| /** | ||
| * Preview a marketing email template before sending to customers. | ||
| */ | ||
| @PostMapping("/marketing/preview") | ||
| public ResponseEntity<String> previewMarketing(@RequestBody RenderRequest request) { | ||
| try { | ||
| String result = marketingService.render(request.getTemplateName(), request.getTemplateContent()); | ||
| return ResponseEntity.ok(result); | ||
| } catch (IOException | TemplateException e) { | ||
| return ResponseEntity.badRequest().body("Preview failed: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Render a notification template with hardened configuration. | ||
| */ | ||
| @PostMapping("/notifications/render") | ||
| public ResponseEntity<String> renderNotification(@RequestBody RenderRequest request) { | ||
| try { | ||
| String result = notificationService.render(request.getTemplateName(), request.getTemplateContent()); | ||
| return ResponseEntity.ok(result); | ||
| } catch (IOException | TemplateException e) { | ||
| return ResponseEntity.badRequest().body("Render failed: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Renders a custom template from user input. | ||
| * Data flows from request body → DTO fields → service → template engine. | ||
| */ | ||
| @PostMapping("/render") | ||
| public ResponseEntity<String> renderTemplate(@RequestBody RenderRequest request) { | ||
| try { | ||
| String result = templateService.renderFromRequest(request); | ||
| return ResponseEntity.ok(result); | ||
| } catch (Exception e) { | ||
| return ResponseEntity.badRequest().body("Template processing failed: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Alternative endpoint demonstrating data flow through object field assignment. | ||
| */ | ||
| @PostMapping("/render/inline") | ||
| public ResponseEntity<String> renderInline(@RequestBody RenderRequest request) { | ||
| try { | ||
| String templateContent = request.getTemplateContent(); | ||
| String result = templateService.renderFromContent(templateContent); | ||
| return ResponseEntity.ok(result); | ||
| } catch (Exception e) { | ||
| return ResponseEntity.badRequest().body("Processing failed: " + e.getMessage()); | ||
| } | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/seqra/spring/content/MarketingTemplateService.java
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,39 @@ | ||
| package org.seqra.spring.content; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.StringReader; | ||
| import java.io.StringWriter; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import freemarker.core.TemplateClassResolver; | ||
| import freemarker.template.Configuration; | ||
| import freemarker.template.Template; | ||
| import freemarker.template.TemplateException; | ||
|
|
||
| @Service | ||
| public class MarketingTemplateService { | ||
|
|
||
| private final Configuration templateConfig; | ||
|
|
||
| public MarketingTemplateService() { | ||
| Configuration templateConfig = new Configuration(Configuration.VERSION_2_3_33); | ||
| templateConfig.setNewBuiltinClassResolver(TemplateClassResolver.UNRESTRICTED_RESOLVER); | ||
| templateConfig.setAPIBuiltinEnabled(true); | ||
| this.templateConfig = templateConfig; | ||
| } | ||
|
|
||
| public String render(String name, String content) throws IOException, TemplateException { | ||
| Template template = new Template(name, new StringReader(content), templateConfig); | ||
|
|
||
| Map<String, Object> model = new HashMap<>(); | ||
| model.put("brandName", "Acme Corp"); | ||
| model.put("campaignId", name); | ||
|
|
||
| StringWriter output = new StringWriter(); | ||
| template.process(model, output); | ||
| return output.toString(); | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
src/main/java/org/seqra/spring/content/NotificationTemplateService.java
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,38 @@ | ||
| package org.seqra.spring.content; | ||
|
|
||
| import freemarker.core.TemplateClassResolver; | ||
| import freemarker.template.Configuration; | ||
| import freemarker.template.Template; | ||
| import freemarker.template.TemplateException; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.StringReader; | ||
| import java.io.StringWriter; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| @Service | ||
| public class NotificationTemplateService { | ||
|
|
||
| private final Configuration templateConfig; | ||
|
|
||
| public NotificationTemplateService() { | ||
| Configuration templateConfig = new Configuration(Configuration.VERSION_2_3_33); | ||
| templateConfig.setNewBuiltinClassResolver(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER); | ||
| templateConfig.setAPIBuiltinEnabled(false); | ||
| this.templateConfig = templateConfig; | ||
| } | ||
|
|
||
| public String render(String name, String content) throws IOException, TemplateException { | ||
| Template template = new Template(name, new StringReader(content), templateConfig); | ||
Check failureCode scanning / OpenTaint Unvalidated user data flows into template engine Error
Potential template injection: unvalidated user data flows into template engine
|
||
|
|
||
| Map<String, Object> model = new HashMap<>(); | ||
| model.put("appName", "Notification Service"); | ||
| model.put("templateId", name); | ||
|
|
||
| StringWriter output = new StringWriter(); | ||
| template.process(model, output); | ||
| return output.toString(); | ||
| } | ||
| } | ||
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,29 @@ | ||
| package org.seqra.spring.content; | ||
|
|
||
| /** | ||
| * DTO for template rendering requests. | ||
| * Data flows from request body through this object's fields. | ||
| */ | ||
| public class RenderRequest { | ||
| private String templateContent; | ||
| private String templateName; | ||
|
|
||
| public RenderRequest() { | ||
| } | ||
|
|
||
| public String getTemplateContent() { | ||
| return templateContent; | ||
| } | ||
|
|
||
| public void setTemplateContent(String templateContent) { | ||
| this.templateContent = templateContent; | ||
| } | ||
|
|
||
| public String getTemplateName() { | ||
| return templateName; | ||
| } | ||
|
|
||
| public void setTemplateName(String templateName) { | ||
| this.templateName = templateName; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/seqra/spring/content/TemplateRenderingService.java
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,41 @@ | ||
| package org.seqra.spring.content; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.thymeleaf.TemplateEngine; | ||
| import org.thymeleaf.context.Context; | ||
| import org.thymeleaf.templatemode.TemplateMode; | ||
| import org.thymeleaf.templateresolver.StringTemplateResolver; | ||
|
|
||
| @Service | ||
| public class TemplateRenderingService { | ||
|
|
||
| private final TemplateEngine templateEngine; | ||
|
|
||
| public TemplateRenderingService() { | ||
| this.templateEngine = new TemplateEngine(); | ||
| StringTemplateResolver resolver = new StringTemplateResolver(); | ||
| resolver.setTemplateMode(TemplateMode.HTML); | ||
| resolver.setCacheable(false); | ||
| this.templateEngine.setTemplateResolver(resolver); | ||
| } | ||
|
|
||
| /** | ||
| * Renders a template from user-provided content. | ||
| * Data flows from the request through templateContent parameter to the TemplateEngine. | ||
| */ | ||
| public String renderFromContent(String templateContent) { | ||
| Context context = new Context(); | ||
| context.setVariable("appName", "Demo Application"); | ||
|
|
||
| return templateEngine.process(templateContent, context); | ||
|
||
| } | ||
|
|
||
| /** | ||
| * Renders a template using the request object. | ||
| * Demonstrates data flow through object field access. | ||
| */ | ||
| public String renderFromRequest(RenderRequest request) { | ||
| String content = request.getTemplateContent(); | ||
| return renderFromContent(content); | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
src/main/java/org/seqra/spring/messaging/CreateMessageRequest.java
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,41 @@ | ||
| package org.seqra.spring.messaging; | ||
|
|
||
| public class CreateMessageRequest { | ||
|
|
||
| private String title; | ||
| private String content; | ||
| private String author; | ||
|
|
||
| public CreateMessageRequest() { | ||
| } | ||
|
|
||
| public CreateMessageRequest(String title, String content, String author) { | ||
| this.title = title; | ||
| this.content = content; | ||
| this.author = author; | ||
| } | ||
|
|
||
| public String getTitle() { | ||
| return title; | ||
| } | ||
|
|
||
| public void setTitle(String title) { | ||
| this.title = title; | ||
| } | ||
|
|
||
| public String getContent() { | ||
| return content; | ||
| } | ||
|
|
||
| public void setContent(String content) { | ||
| this.content = content; | ||
| } | ||
|
|
||
| public String getAuthor() { | ||
| return author; | ||
| } | ||
|
|
||
| public void setAuthor(String author) { | ||
| this.author = author; | ||
| } | ||
| } |
Oops, something went wrong.
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.
Check failure
Code scanning / OpenTaint
Unvalidated user data flows into template engine Error