Skip to content

Commit

Permalink
Merge pull request #68 from fritzmg/allow-unsafed-hash-parameters
Browse files Browse the repository at this point in the history
Allow 'unsafe-hashed-attributes' to be set
  • Loading branch information
paragonie-security authored Mar 26, 2023
2 parents f6367bf + db6b4f1 commit acdda0e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/CSPBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,23 @@ public function setAllowUnsafeInline(string $directive = '', bool $allow = false
return $this;
}

/**
* Allow/disallow unsafe-hashed-attributes within a given directive.
*
* @param string $directive
* @param bool $allow
* @return self
* @throws Exception
*/
public function setAllowUnsafeHashedAttributes(string $directive = '', bool $allow = false): self
{
if (!in_array($directive, self::$directives)) {
throw new Exception('Directive ' . $directive . ' does not exist');
}
$this->policies[$directive]['unsafe-hashed-attributes'] = $allow;
return $this;
}

/**
* Allow/disallow blob: URIs for a given directive
*
Expand Down
13 changes: 13 additions & 0 deletions test/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,19 @@ public function testSaveSnippetWithoutHookBeforeSave()
);
}

/**
* @covers CSPBuilder::setAllowUnsafeEval()
* @throws \Exception
*/
public function testAllowUnsafeHashedAttributes()
{
$csp = new CSPBuilder();
$csp->setAllowUnsafeHashedAttributes('script-src', true);
$compiled = $csp->compile();

$this->assertStringContainsString("'unsafe-hashed-attributes'", $compiled);
}

/**
* @covers CSPBuilder::allowPluginType()
* @throws \Exception
Expand Down

0 comments on commit acdda0e

Please sign in to comment.