Shopify

How to Add Iframe Protection in Shopify-Laravel Embedded Apps

Shopify App Store is the best place to accelerate your sellings and grow your business. When you submit your app to the Shopify App Store it might get rejected. This may be because the content security policy is not set properly.

Shopify Apps on the Shopify App Store must set proper Content Security Policy frame-ancestors directive in order to avoid clickjacking attacks. You face App rejection from the Shopify App Store in case the Content Security Policy frame-ancestors directive is not set properly or is missing. Check out the latest Shopify editions with 100+ new products and updates.

Embedded Shopify Apps

For Embedded Apps you need to make sure that the app can only be frameable by authenticated domain. Set the frame-ancestors directive on the basis of the current shop domain and Shopify admin domain. This will ensure that the app can be framed within the shop domain only.

Let’s learn How to Add Iframe Protection in Shopify-Laravel Embedded Apps

Steps to Add Iframe Protection in Shopify-Laravel Embedded Apps

Step 1:  Create middleware

First, you need to create middleware in your project using the following command

php artisan make:middleware FrameHeadersMiddleware

Step 2: Add code in middleware

Put the following code in middleware

public function handle(Request $request, Closure $next)
{
     $response = $next($request);
     $user = \Auth::user();

     if($user)
     {
          $response->header('Content-Security-Policy', "frame-ancestors https://{$user- >name} https://admin.shopify.com");
     }

     return $response;
}

Step 3: Define middleware in the app/http/kernel.php file 

protected $routeMiddleware 

   'cus.header' =>\App\Http\Middleware\FrameHeadersMiddleware::class,

Step 4: Assign middleware in routes 

Route::get('/dashboard', [TestController::class, 'index'])

->middleware('cus.header');

How to Check frame-ancestors in Shopify App?

Step 1: From your Shopify Shop, select Apps.

Step 2: Now, right-click anywhere on the page and select Inspect.

Step 3: Select the Network tab.

Step 4: Select the last document from the list. And click the Headers tab.

Step 5: Check if the frame-ancestors directive is included as below or not

content-security-policy: frame-ancestors https://abc.myshopify.com https://admin.shopify.com

If the directive is correctly included your app is secure.

Shopify Apps that are not Embedded

If your app isn’t embedded, then you can set the frame-ancestors directive to ‘none’ in order to disallow framing.

Content-Security-Policy: frame-ancestors 'none';

Closure:

This way you can Add Iframe Protection in Shopify Embedded Apps. If you face any trouble in securing your Shopify App, you can reach out to our Shopify Masters to get it done. Share the tutorial with your Shopify friends to help them secure their apps.

Happy Reading!

Click to rate this post!
[Total: 3 Average: 3.7]
Bharat Desai

Bharat Desai is a Co-Founder at MageComp. He is an Adobe Magento Certified Frontend Developer 🏅 with having 8+ Years of experience and has developed 150+ Magento 2 Products with MageComp. He has an unquenchable thirst to learn new things. On off days you can find him playing the game of Chess ♟️ or Cricket 🏏.

View Comments

  • Hello Sir

    Updates required for embedded apps to work on the new Shopify admin domain

    Top Product Review App is outdated

    This app is outdated and will no longer function after Wednesday, September 6, 2023. Contact the app's developer to update the app.

    We have updated frameable by authenticated domain. Set the frame-ancestors directive on the basis of the current shop domain and Shopify admin domain.

    But not working still

    Can you help me please

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

22 hours ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

3 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

3 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

4 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

5 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago