Welcome Guest, Not a member yet? Register   Sign In
Allow inline style attibute on element using Content Security Policy (CSP)
#1

(This post was last modified: 09-23-2021, 07:53 AM by coderscvoen. Edit Reason: updated the background image path )

Hi, l need help with this. Am showing an image from the database (the image is in a folder while the path is stored in the database) on a slider. I have enabled Content Security Policy from the "Config/App.php" and everything is working fine except this. The image is not being displayed since am showing it as inline style. Was wondering how to allow inline styling in CSP. The example they gave in the documentation does not seem to cover this. Since this image is dynamic, i can't move it to an external style. Any assistance is appreciated.
PHP Code:
<div class="single-slider hero-overly slider-height d-flex align-items-center" style="
background-image: url('<?= base_url(
$sliderimages['image_path']); ?>');">
<
div class="slider-description-text-block">
<
p><?= $sliderimages['image_info']; ?></p>
</div>
</div> 

Here is the css CSP part.
PHP Code:
$response->CSP->setDefaultSrc('self');
$response->CSP->addFontSrc(['self''https://fonts.googleapis.com''https://fonts.gstatic.com']);
$response->CSP->addImageSrc('self');
$response->CSP->addScriptSrc('self'false);
$response->CSP->addStyleSrc(['self''https://fonts.googleapis.cm'], false); 
Reply


Messages In This Thread
Allow inline style attibute on element using Content Security Policy (CSP) - by coderscvoen - 09-22-2021, 09:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB