Security

Basic Authentication

BasicAuth is an authentication scheme built into the HTTP protocol. As long as the client transmits its data over HTTPS, it’s a secure authentication mechanism.

Authorization: Basic YXBpLXVzZXI6c2VjcmV0

The tuupola/slim-basic-auth package implements HTTP Basic Authentication.

OAuth 2.0

For authorization, you could consider to use OAuth 2.0 in combination with a signed JSON Web Token.

The JWTs can be used as OAuth 2.0 Bearer-Tokens to encode all relevant parts of an access token into the access token itself instead of having to store them in a database.

Please note: OAuth 2.0 is not an authentication protocol.

Clients may use the HTTP Basic authentication scheme, as defined in RFC2617, to authenticate with the server.

After successful authentication, the client sends its token within the Authorization request header:

Authorization: Bearer RsT5OjbzRn430zqMLgV3Ia

The lcobucci/jwt and firebase/php-jwt packages are a very good tools to work with JSON Web Tokens.

Cross-site Request Forgery (CSRF) Protection

Cross-site request forgery (CSRF) is a web security vulnerability that tricks a victim’s browser into performing unwanted actions on a web application where the user is authenticated, without their knowledge or consent.

SameSite Cookies can be used for security purposes to prevent CSRF attacks, by controlling whether cookies are sent along with cross-site requests, thereby limiting the risk of third-party interference with the intended functioning of web applications.

Cross-Origin Resource Sharing (CORS)

Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers that controls how web pages in one domain can request resources from another domain, aiming to safely enable interactions between different origins.

Cross Site Scripting (XSS) Prevention

Cross-site Scripting (XSS) is a client-side code injection attack. The attacker aims to execute malicious scripts in a web browser of the victim by including malicious code in a legitimate web page or web application.

To prevent XSS you can use an Auto-Escaping Template System such as Twig or by using libraries that are specifically designed to sanitize HTML input:

More Resources