Procházet zdrojové kódy

Set cookie security using useHttps config option

Zed před 7 roky
rodič
revize
c2413ccfdd
3 změnil soubory, kde provedl 4 přidání a 2 odebrání
  1. 1 0
      src/config.nim
  2. 2 2
      src/nitter.nim
  3. 1 0
      src/types.nim

+ 1 - 0
src/config.nim

@@ -15,6 +15,7 @@ proc getConfig*(path: string): Config =
   Config(
     address: cfg.get("Server", "address", "0.0.0.0"),
     port: cfg.get("Server", "port", 8080),
+    useHttps: cfg.get("Server", "https", true),
     title: cfg.get("Server", "title", "Nitter"),
     staticDir: cfg.get("Server", "staticDir", "./public"),
 

+ 2 - 2
src/nitter.nim

@@ -89,13 +89,13 @@ routes:
   post "/saveprefs":
     var prefs = cookiePrefs()
     genUpdatePrefs()
-    setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=true)
+    setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=cfg.useHttps)
     redirect("/")
 
   post "/resetprefs":
     var prefs = cookiePrefs()
     resetPrefs(prefs)
-    setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=true)
+    setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=cfg.useHttps)
     redirect("/settings")
 
   get "/settings":

+ 1 - 0
src/types.nim

@@ -167,6 +167,7 @@ type
   Config* = ref object
     address*: string
     port*: int
+    useHttps*: bool
     title*: string
     staticDir*: string
     cacheDir*: string