A Simple Cross Origin Resource Sharing for Lumen Framework (5.*).

Related tags

Security lumen-cors
Overview

Lumen Cors Package

Join the chat at https://gitter.im/vluzrmos/lumen-cors

Lumen Version Latest Stable Version Total Downloads License Build Status StyleCI Scrutinizer Code Quality

A Simple Cross Origin Resource Sharing for Lumen Framework.

Note: That should works fine on Laravel Framework too, but the tests are performed to Lumen.

Install

composer require "vluzrmos/lumen-cors=2.1.*"

Configure

On boostrap/app.php register the middleware:

$app->middleware([
	//...,
	'Vluzrmos\LumenCors\CorsMiddleware'
]);

You are free to use ::class notation.

And that is it!

Considerations

That package stands to be free of configurations, then if you want a more configurable package please consider to see one of these:

Comments
  • allow any Symfony Response object

    allow any Symfony Response object

    Hey there. I like your middleware, but can't use it because I have a case where I'm using Laravel\Lumen\Http\ResponseFactory::download to return a download response, which is an instance of Symfony\Something\BinaryFileResponse. Symfony Response objects don't have the header() method, which is added by Laravel, but is a simple passthrough to $this->headers->set().

    So anyway, by using the parent class, you make this middleware more flexible, and typehinting the SymfonyResponse doesn't break anything because all Illuminate\Http\Response objects are instances of the parent Symfony object.

    opened by jaredh159 6
  • Request with credentials not working due to Origin: *

    Request with credentials not working due to Origin: *

    As per https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials "when responding to a credentialed request, server must specify a domain, and cannot use wild carding".

    CorsService::getCorsHeaders() currently has 'Access-Control-Allow-Origin' => '*',. If this where changed to 'Access-Control-Allow-Origin' => $request->headers->get('Origin') ?: '*', then credentialed requests will also work.

    @vluzrmos is this a change you would be OK with? If so, would you like a pull request?

    opened by jorygeerts 4
  • Problems with custom routes

    Problems with custom routes

    When use custom routes like "$app->get('/user/{id}')" the server respond with code 405, like the route don't exist. I've look and probably is something with this line in CorsServiceProvider class:

    $this->app->options($request->path(), function(){ return new Response('OK', 200); });

    I think that Laravel is considering the fixed route /user/3 instead of /user/{id} and the GET method

    opened by jaswdr 3
  • Dependency conflict with lumen V6

    Dependency conflict with lumen V6

    This package has a conflict with illuminate/support, while trying to upgrade to lumen v6. Please

    Please check the following error log.

    `` Problem 1 - illuminate/http 5.4.x-dev requires illuminate/session 5.4.* -> satisfiable by illuminate/session[5.4.x-dev, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9]. - illuminate/http v5.4.0 requires illuminate/session 5.4.* -> satisfiable by illuminate/session[5.4.x-dev, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9]. - illuminate/http v5.4.13 requires illuminate/session 5.4.* -> satisfiable by illuminate/session[5.4.x-dev, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9]. - illuminate/http v5.4.17 requires illuminate/session 5.4.* -> satisfiable by

    Conclusion: don't install laravel/framework v6.0.2|install vluzrmos/lumen-cors v2.1.2 - Installation request for vluzrmos/lumen-cors 2.1. -> satisfiable by vluzrmos/lumen-cors[2.1.x-dev, v2.1.0, v2.1.1, v2.1.2].* ``

    opened by MaherSaleem 2
  • Not working with clear install

    Not working with clear install

    I've installed on a fresh copy of lumen but doesn't works, trace:

    405 - MethodNotAllowedHttpException

    in Application.php line 1176
    at Application->handleDispatcherResponse(array('2', array('POST', 'GET'))) in Application.php line 1131
    at Application->Laravel\Lumen\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CorsMiddleware.php line 26
    at CorsMiddleware->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(CorsMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
    at StartSession->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in Application.php line 1352
    at Application->sendThroughPipeline(array('Illuminate\Session\Middleware\StartSession', 'Vluzrmos\LumenCors\Middlewares\CorsMiddleware'), object(Closure)) in Application.php line 1132
    at Application->dispatch(null) in Application.php line 1072
    at Application->run() in index.php line 28
    at require_once('E:\projetos\testeCors\public\index.php') in server.php line 12
    

    I test with a simple OPTIONS request to the server and Lumen 5.1

    opened by jaswdr 2
  • Response is now generic [Fix for JSONResponse]

    Response is now generic [Fix for JSONResponse]

    Was having issues because the parameter of setCorsHeaders was expecting a Response object, however it was receiving a JsonResponse object. Made the parameter expect a generic variable rather than an explicit "Response"

    opened by mattpatterson94 2
  • Symfony update of Request class requiring a second argument for setTrustedProxies

    Symfony update of Request class requiring a second argument for setTrustedProxies

    Hi,

    After an update of all my dependencies (running Lumen 5.4), I noticed the following error:

    The Symfony\\Component\\HttpFoundation\\Request::setTrustedProxies() method expects a bit field of Request::HEADER_* as second argument. Defining it is required since version 3.3. See http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info.

    Documentation in the file Request shows for argument trustedHeaderSet of setTrustedProxiesmethod:

    /**
     * @param int   $trustedHeaderSet A bit field of Request::HEADER_*, usually either Request::HEADER_FORWARDED or Request::HEADER_X_FORWARDED_ALL, to set which headers to trust from your proxies
     */
    

    It seems that the line:

    $request->setTrustedProxies($request->getClientIps());
    

    Should also implement the following:

    $request->setTrustedProxies($request->getClientIps(), Request::HEADER_X_FORWARDED_ALL);
    

    Or something like this :)

    Thanks !

    opened by EdwinDayot 1
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    vluzrmos/lumen-cors now has a Chat Room on Gitter

    @vluzrmos has just created a chat room. You can visit it here: https://gitter.im/vluzrmos/lumen-cors.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
Releases(v2.1.2)
Owner
Vagner Luz do Carmo
PHP | Node | Golang Developer.
Vagner Luz do Carmo
PHP CORS (Cross-origin resource sharing) middleware.

CORS PHP CORS (Cross-origin resource sharing) middleware. Support Array, Coding in Native PHP Using PSR-7 PSR-15 Support Symfony Support Laravel Suppo

Seven Du 269 Nov 9, 2022
A simple php (lumen) app for sharing sensitive text (basically like onetimesecret), but with full end-to-end AES-256-GCM encryption so even the server has no access to the data, and developed with very simple deployment in mind.

A simple php (lumen) app for sharing sensitive text (basically like onetimesecret), but with full end-to-end AES-256-GCM encryption so even the server has no access to the data, and developed with very simple deployment in mind.

Alan Woo 51 Nov 21, 2022
㊙️ AntiXSS | Protection against Cross-site scripting (XSS) via PHP

㊙️ AntiXSS "Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web applications. XSS enables attackers to inje

Lars Moelleken 570 Dec 16, 2022
Security CSRF (cross-site request forgery) component provides a class CsrfTokenManager for generating and validating CSRF tokens.

Security Component - CSRF The Security CSRF (cross-site request forgery) component provides a class CsrfTokenManager for generating and validating CSR

Symfony 1.5k Jan 3, 2023
CORS Middleware for Lumen micro-framework

Lumen-CORS Cross-origin resource sharing (CORS) Middleware for Lumen micro-framework. Installation After you install lumen as per lumen docs, install

Palani Kumanan 101 Nov 21, 2022
Laravel and Lumen Source Code Encrypter

Laravel Source Encrypter This package encrypts your php code with phpBolt For Laravel and Lumen 6, 7, 8 Installation Usage Installation Step 1 At the

Siavash Bamshadnia 363 Jan 1, 2023
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.6k Jan 6, 2023
Cryptographic component from Zend Framework

zend-crypt Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-crypt. Zend\Crypt provides support of some cryptographic tools

Zend Framework 89 Dec 4, 2021
Simple Encryption in PHP.

php-encryption composer require defuse/php-encryption This is a library for encrypting data with a key or password in PHP. It requires PHP 5.6 or new

Taylor Hornby 3.6k Jan 3, 2023
PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web application

PHPIDS PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web ap

null 752 Jan 3, 2023
TCrypto is a simple and flexible PHP 5.3+ in-memory key-value storage library

About TCrypto is a simple and flexible PHP 5.3+ in-memory key-value storage library. By default, a cookie will be used as a storage backend. TCrypto h

timoh 57 Dec 2, 2022
A simple, yet feature rich password manager for Nextcloud

Easy to use yet feature-rich and secure password manager for Nextcloud

M. Wieschollek 169 Jan 3, 2023
A simple PHP web backdoor allows you to retrieve directory/file contents and upload file(s) from the local machine or remote URL.

Simple PHP Web Backdoor A simple PHP web backdoor allows you to retrieve directory/file contents and upload file(s) from the local machine or remote U

Aqhmal Hafizi 15 Oct 7, 2022
encrypt HMAC SHA1 with simple PHP

HMAC Tugas UTS SKJ 1 MALAM Nama : MOCHAMMAD SIDIQ C.A. NIM : 1814321019 Create Hmac Buka terminal powershell pada visual studioCode (dahal hal ini

Shidiq Mochsi 2 Jan 10, 2022
Security advisories as a simple composer exclusion list, updated daily

Roave Security Advisories This package ensures that your application doesn't have installed dependencies with known security vulnerabilities. Installa

Roave, LLC 2.5k Jan 5, 2023
A cryptography API wrapping the Sodium library, providing a simple object interface for symmetrical and asymmetrical encryption, decryption, digital signing and message authentication.

PHP Encryption A cryptography API wrapping the Sodium library, providing a simple object interface for symmetrical and asymmetrical encryption, decryp

null 19 Dec 31, 2022
CORS (Cross-Origin Resource Sharing) support for Laravel and Lumen

Description This package adds Cross-Origin Resource Sharing (CORS) support to your Laravel application. The package is based on Framework agnostic (PS

null 48 Feb 1, 2020
This package has framework agnostic Cross-Origin Resource Sharing (CORS) implementation.

Description This package has framework agnostic Cross-Origin Resource Sharing (CORS) implementation. It is complaint with PSR-7 HTTP message interface

null 60 Nov 9, 2022
Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application

CORS Middleware for Laravel Implements https://github.com/asm89/stack-cors for Laravel About The laravel-cors package allows you to send Cross-Origin

Fruitcake 6.2k Jan 8, 2023