File size: 1,457 Bytes
c24174e
eed224b
c24174e
 
 
eed224b
cd60ce3
0fb7b7d
eed224b
 
0a48e3f
 
3980956
 
 
0a48e3f
eed224b
 
 
 
 
c01a583
 
3980956
 
eed224b
 
a73f02a
eed224b
 
 
 
 
cd60ce3
c24174e
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Koa from "koa";
import bodyParser from "koa-bodyparser";

const app = new Koa();

app.use(bodyParser());

app.use(async (ctx) => {
  if (ctx.request.method === "POST") {
    const { cookie } = ctx.request.body as { cookie: string };
    ctx.set("Set-Cookie", [
      `cookie-none=${cookie.replace(/[^A-Za-z0-9]+/g, '-')}; SameSite=None; Secure`,
      `cookie-lax=${cookie.replace(/[^A-Za-z0-9]+/g, '-')}; SameSite=Lax; Secure`,
      `cookie-none-top-level=${cookie.replace(/[^A-Za-z0-9]+/g, '-')}; SameSite=None; Secure; Domain=hf.space`,
      `cookie-lax-top-level=${cookie.replace(/[^A-Za-z0-9]+/g, '-')}; SameSite=Lax; Secure; Domain=hf.space`,
    ]);
    ctx.redirect( "/");
  } else {
    ctx.body = `<html>
    <body>
      <pre>${JSON.stringify(Object.fromEntries(Object.entries(ctx.request.headers)), null, 2)}</pre>
      <p>Cookie SameSite=None: ${ctx.cookies.get("cookie-none")?.replace(/</g, '$lt;')}</p>
      <p>Cookie SameSite=Lax: ${ctx.cookies.get("cookie-lax")?.replace(/</g, '$lt;')}</p>
      <p>Cookie SameSite=None Top-Level: ${ctx.cookies.get("cookie-none-top-level")?.replace(/</g, '$lt;')}</p>
      <p>Cookie SameSite=Lax Top-Level: ${ctx.cookies.get("cookie-lax-top-level")?.replace(/</g, '$lt;')}</p>
      <form method="POST">
        <label>Cookie value<br>
          <input type="text" name="cookie" />
        </label>
        <button>Send</button>
      </form>
    </body>
  </html>`;
  }
});

app.listen(7860);