cutelyst 4.0.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
csrfprotection.h
1/*
2 * SPDX-FileCopyrightText: (C) 2017-2022 Matthias Fehring <mf@huessenbergnetz.de>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef CSRFPROTECTION_H
7#define CSRFPROTECTION_H
8
9#include <Cutelyst/Plugin>
10#include <Cutelyst/cutelyst_global.h>
11
12namespace Cutelyst {
13
14class Context;
15class CSRFProtectionPrivate;
16
248class CUTELYST_PLUGIN_CSRFPROTECTION_EXPORT CSRFProtection
249 : public Plugin // clazy:exclude=ctor-missing-parent-argument
250{
251 Q_OBJECT
252 Q_DECLARE_PRIVATE(CSRFProtection) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
253 Q_DISABLE_COPY(CSRFProtection)
254public:
259
263 ~CSRFProtection() override;
264
271 void setDefaultDetachTo(const QString &actionNameOrPath);
272
277 void setFormFieldName(const QByteArray &fieldName);
278
283 void setErrorMsgStashKey(const QString &keyName);
284
290 void setIgnoredNamespaces(const QStringList &namespaces);
291
299 void setUseSessions(bool useSessions);
300
317 void setCookieHttpOnly(bool httpOnly);
318
324 void setCookieName(const QByteArray &cookieName);
325
330 void setHeaderName(const QByteArray &headerName);
331
338 void setGenericErrorMessage(const QString &message);
339
345 void setGenericErrorContentType(const QByteArray &type);
346
350 static QByteArray getToken(Context *c);
351
363 static QString getTokenFormField(Context *c);
364
372 static bool checkPassed(Context *c);
373
374protected:
375 bool setup(Application *app) override;
376
377private:
378 const std::unique_ptr<CSRFProtectionPrivate> d_ptr;
379};
380
381} // namespace Cutelyst
382
383#endif // CSRFPROTECTION_H
The Cutelyst Application.
Definition: application.h:43
Protect input forms against Cross Site Request Forgery (CSRF/XSRF) attacks.
The Cutelyst Context.
Definition: context.h:38
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8