Package com.helger.http.csp
Class AbstractCSPSourceList<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>>
java.lang.Object
com.helger.http.csp.AbstractCSPSourceList<IMPLTYPE>
- Type Parameters:
IMPLTYPE- Implementation type
- All Implemented Interfaces:
com.helger.base.trait.IGenericImplTrait<IMPLTYPE>
- Direct Known Subclasses:
CSPSourceList
@NotThreadSafe
public abstract class AbstractCSPSourceList<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>>
extends Object
implements com.helger.base.trait.IGenericImplTrait<IMPLTYPE>
A source list to be used in a CSP directive (
CSPDirective). It's just a convenient way to
build a CSP directive value.- Author:
- Philip Helger
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddHash(com.helger.security.messagedigest.EMessageDigestAlgorithm eMDAlgo, byte[] aHashValue) Add the provided nonce value.Add the provided Base64 encoded hash value.addHost(com.helger.url.ISimpleURL aHost) Add a hostAdd a hostsource expression 'none' represents an empty set of URIsIf this expression is included in a directive controlling scripts or styles, and the directive causes the browser to block any inline scripts, inline styles, or event handler attributes, then the violation report that the browser generates will contain a sample property containing the first 40 characters of the blocked resource.source expression 'self' represents the set of URIs which are in the same origin as the protected resourceThe 'strict-dynamic' keyword makes the trust conferred on a script by a nonce or a hash extend to scripts that this script dynamically loads, for example by creating new <script> tags using Document.createElement() and then inserting them into the document using Node.appendChild().By default, if a CSP contains a default-src or a script-src directive, then JavaScript functions which evaluate their arguments as JavaScript are disabled.source expression 'unsafe-inline' represents content supplied inline in the resource itselfaddMimeType(com.helger.mime.IMimeType aMimeType) Add a MIME type (for plugin-types)addNonce(byte[] aNonceValue) Add the provided nonce value.Add the provided Base64 encoded nonce value.Add a schemebooleanintinthashCode()toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.base.trait.IGenericImplTrait
thisAsT
-
Field Details
-
KEYWORD_NONE
- See Also:
-
KEYWORD_REPORT_SAMPLE
- See Also:
-
KEYWORD_SELF
- See Also:
-
KEYWORD_STRICT_DYNAMIC
- See Also:
-
KEYWORD_UNSAFE_INLINE
- See Also:
-
KEYWORD_UNSAFE_EVAL
- See Also:
-
NONCE_PREFIX
- See Also:
-
NONCE_SUFFIX
- See Also:
-
HASH_PREFIX
- See Also:
-
HASH_SUFFIX
- See Also:
-
-
Constructor Details
-
AbstractCSPSourceList
public AbstractCSPSourceList()
-
-
Method Details
-
getExpressionCount
@Nonnegative public int getExpressionCount() -
addScheme
Add a scheme- Parameters:
sScheme- Scheme in the formatscheme ":"- Returns:
- this
-
addHost
Add a host- Parameters:
aHost- Host to add. Must be a valid URL.- Returns:
- this
-
addHost
Add a host- Parameters:
sHost- Host to add. Must be a valid URL or a star prefixed version.- Returns:
- this
-
addMimeType
Add a MIME type (for plugin-types)- Parameters:
aMimeType- MIME type to add. May not benull.- Returns:
- this
-
addKeywordNone
source expression 'none' represents an empty set of URIs- Returns:
- this
-
addKeywordReportSample
If this expression is included in a directive controlling scripts or styles, and the directive causes the browser to block any inline scripts, inline styles, or event handler attributes, then the violation report that the browser generates will contain a sample property containing the first 40 characters of the blocked resource.- Returns:
- this
-
addKeywordSelf
source expression 'self' represents the set of URIs which are in the same origin as the protected resource- Returns:
- this
-
addKeywordStrictDynamic
The 'strict-dynamic' keyword makes the trust conferred on a script by a nonce or a hash extend to scripts that this script dynamically loads, for example by creating new <script> tags using Document.createElement() and then inserting them into the document using Node.appendChild().- Returns:
- this
-
addKeywordUnsafeEval
By default, if a CSP contains a default-src or a script-src directive, then JavaScript functions which evaluate their arguments as JavaScript are disabled. This includes "eval()", the code argument to "setTimeout()", or the "Function()" constructor.- Returns:
- this
-
addKeywordUnsafeInline
source expression 'unsafe-inline' represents content supplied inline in the resource itself- Returns:
- this
-
addNonce
Add the provided nonce value. The "\'nonce-"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andNONCE_SUFFIXare added automatically. The byte array is automatically Bas64 encoded.- Parameters:
aNonceValue- The plain nonce bytes. May not benull.- Returns:
- this for chaining
-
addNonce
Add the provided Base64 encoded nonce value. The "\'nonce-"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andNONCE_SUFFIXare added automatically.- Parameters:
sNonceBase64Value- The Base64 encoded nonce value- Returns:
- this for chaining
-
addHash
@Nonnull public IMPLTYPE addHash(@Nonnull com.helger.security.messagedigest.EMessageDigestAlgorithm eMDAlgo, @Nonnull @Nonempty byte[] aHashValue) Add the provided nonce value. The "\'"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andHASH_SUFFIXare added automatically. The byte array is automatically Bas64 encoded!- Parameters:
eMDAlgo- The message digest algorithm used. May onlyEMessageDigestAlgorithm.SHA_256,EMessageDigestAlgorithm.SHA_384orEMessageDigestAlgorithm.SHA_512. May not benull.aHashValue- The plain hash digest value. May not benull.- Returns:
- this for chaining
-
addHash
@Nonnull public IMPLTYPE addHash(@Nonnull com.helger.security.messagedigest.EMessageDigestAlgorithm eMDAlgo, @Nonnull String sHashBase64Value) Add the provided Base64 encoded hash value. The "\'"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andHASH_SUFFIXare added automatically.- Parameters:
eMDAlgo- The message digest algorithm used. May onlyEMessageDigestAlgorithm.SHA_256,EMessageDigestAlgorithm.SHA_384orEMessageDigestAlgorithm.SHA_512. May not benull.sHashBase64Value- The Base64 encoded hash value- Returns:
- this for chaining
-
getAsString
- Returns:
- The whole source list as a single string, separated by a blank char.
-
equals
-
hashCode
public int hashCode() -
toString
-