detached 7c6200e

Sanitize the form inputs once received

commit
7c6200e50695ca10a7128439731d46058eec22b5
author
bnema · · 2023-09-25 08:55 UTC
parent
860e07b
signature
unsigned
3 files · +34 -5
M internal/gotemplate/models/html/fragments/createcontainer.gohtml +1 -1
@@ -39,7 +39,7 @@
3939 <label class="block">Domain/Subdomain</label>
4040 <input
4141 type="text"
42- name="container_name"
42+ name="container_domain"
4343 class="w-full p-4 rounded-md"
4444 value="{{.ContainerDomain}}"
4545 />
@@ -39,7 +39,7 @@
39 <label class="block">Domain/Subdomain</label>39 <label class="block">Domain/Subdomain</label>
40 <input40 <input
41 type="text"41 type="text"
42- name="container_name"42+ name="container_domain"
43 class="w-full p-4 rounded-md"43 class="w-full p-4 rounded-md"
44 value="{{.ContainerDomain}}"44 value="{{.ContainerDomain}}"
45 />45 />
M internal/gotemplate/models/html/fragments/leftmenu.gohtml +8 -2
@@ -27,11 +27,17 @@
2727 <i class="iconoir-server mr-2 md:text-3xl"></i>
2828 <a href="/admin/manager">Manager</a>
2929 </li>
30- <li class="flex items-center w-1/2 md:w-full text-gray-600">
30+ <li
31+ class="flex items-center w-1/2 md:w-full text-gray-600"
32+ style="display: none"
33+ >
3134 <i class="iconoir-community mr-2 md:text-3xl"></i>
3235 <a title="Disabled" href="#">Users</a>
3336 </li>
34- <li class="flex items-center w-1/2 md:w-full text-gray-600">
37+ <li
38+ class="flex items-center w-1/2 md:w-full text-gray-600"
39+ style="display: none"
40+ >
3541 <i class="iconoir-database-settings mr-2 md:text-3xl"></i>
3642 <a title="Disabled" href="#">Settings</a>
3743 </li>
@@ -27,11 +27,17 @@
27 <i class="iconoir-server mr-2 md:text-3xl"></i>27 <i class="iconoir-server mr-2 md:text-3xl"></i>
28 <a href="/admin/manager">Manager</a>28 <a href="/admin/manager">Manager</a>
29 </li>29 </li>
30- <li class="flex items-center w-1/2 md:w-full text-gray-600">30+ <li
31+ class="flex items-center w-1/2 md:w-full text-gray-600"
32+ style="display: none"
33+ >
31 <i class="iconoir-community mr-2 md:text-3xl"></i>34 <i class="iconoir-community mr-2 md:text-3xl"></i>
32 <a title="Disabled" href="#">Users</a>35 <a title="Disabled" href="#">Users</a>
33 </li>36 </li>
34- <li class="flex items-center w-1/2 md:w-full text-gray-600">37+ <li
38+ class="flex items-center w-1/2 md:w-full text-gray-600"
39+ style="display: none"
40+ >
35 <i class="iconoir-database-settings mr-2 md:text-3xl"></i>41 <i class="iconoir-database-settings mr-2 md:text-3xl"></i>
36 <a title="Disabled" href="#">Settings</a>42 <a title="Disabled" href="#">Settings</a>
37 </li>43 </li>
M internal/httpserve/handler/createcontainer.go +25 -2
@@ -6,6 +6,7 @@ import (
66 "github.com/bnema/gordon/internal/app"
77 "github.com/bnema/gordon/internal/gotemplate/render"
88 "github.com/bnema/gordon/pkg/utils/docker"
9+ "github.com/bnema/gordon/pkg/utils/sanitize"
910 "github.com/labstack/echo/v4"
1011 )
1112
@@ -96,6 +97,28 @@ func CreateContainerPOST(c echo.Context, a *app.App) error {
9697 return sendError(c, err)
9798 }
9899
99- // Redirect to the container manager
100- return c.Redirect(302, "/htmx/container-manager")
100+ // Retrieve all form parameters
101+ formParams, err := c.FormParams()
102+ if err != nil {
103+ return sendError(c, err)
104+ }
105+
106+ // Initialize a map to store sanitized values
107+ sanitizedParams := make(map[string]string)
108+
109+ // Iterate over all form parameters and sanitize them
110+ for k, v := range formParams {
111+ if len(v) > 0 {
112+ sanitized, err := sanitize.SanitizeHTML(v[0])
113+ if err != nil {
114+ return sendError(c, err)
115+ }
116+ sanitizedParams[k] = sanitized
117+ }
118+ }
119+
120+ // Print the form values
121+ fmt.Printf("Form values: %v\n", sanitizedParams)
122+
123+ return c.String(200, "OK")
101124 }
@@ -6,6 +6,7 @@ import (
6 "github.com/bnema/gordon/internal/app"6 "github.com/bnema/gordon/internal/app"
7 "github.com/bnema/gordon/internal/gotemplate/render"7 "github.com/bnema/gordon/internal/gotemplate/render"
8 "github.com/bnema/gordon/pkg/utils/docker"8 "github.com/bnema/gordon/pkg/utils/docker"
9+ "github.com/bnema/gordon/pkg/utils/sanitize"
9 "github.com/labstack/echo/v4"10 "github.com/labstack/echo/v4"
10 )11 )
11 12
@@ -96,6 +97,28 @@ func CreateContainerPOST(c echo.Context, a *app.App) error {
96 return sendError(c, err)97 return sendError(c, err)
97 }98 }
98 99
99- // Redirect to the container manager100+ // Retrieve all form parameters
100- return c.Redirect(302, "/htmx/container-manager")101+ formParams, err := c.FormParams()
102+ if err != nil {
103+ return sendError(c, err)
104+ }
105+
106+ // Initialize a map to store sanitized values
107+ sanitizedParams := make(map[string]string)
108+
109+ // Iterate over all form parameters and sanitize them
110+ for k, v := range formParams {
111+ if len(v) > 0 {
112+ sanitized, err := sanitize.SanitizeHTML(v[0])
113+ if err != nil {
114+ return sendError(c, err)
115+ }
116+ sanitizedParams[k] = sanitized
117+ }
118+ }
119+
120+ // Print the form values
121+ fmt.Printf("Form values: %v\n", sanitizedParams)
122+
123+ return c.String(200, "OK")
101 }124 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close