Content Security Policy blocking a blob resource

0 0
Read Time:1 Minute, 16 Second

I have a page with extensive use of a fairly old JavaScript library, that does not load properly in Firefox and I only get the error message:

Content Security Policy: The page’s settings blocked the loading of a resource at blob:http://localhost:8080/32e24021-9c34-4bcf-ad29-a1bf9dd87066 (“script-src”).

This is strange, because the page does not contain this resource (it must be loaded dynamically). Also, the content security policy set in the header supposedly allows this script to load:

Content-Security-Policy: default-src 'self';style-src 'self' 'unsafe-inline';object-src 'none';frame-src 'none';frame-ancestors 'none';script-src 'self' 'unsafe-inline' 'unsafe-eval'

The page loads in Chrome, but there is also an error message there:

jstree.min.js:2 Refused to create a worker from 'blob:http://localhost:8080/212343a2-b80f-4ea5-8013-6cce3fa10265' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'". Note that 'worker-src' was not explicitly set, so 'script-src' is used as a fallback.

This makes it a bit more clear, what’s happening:

  1. This is a worker
  2. Workers are controlled by worker-src, but as it’s not defined, script-src is the fallback option.
  3. script-src is not enough to allow this worker (localhost is not covered by 'self', because this is a blob: and not just any resource)

The solution is to add worker-src blob: to the Content-Security-Policy header. Note that adding worker-src 'blob:' does not help.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

@IdClass required for a @ManyToOne column

0 0
Read Time:1 Minute, 4 Second

Having a JPA entity (e.g. CompanyAddress) with a somewhat strange primary key setup, where the primary key is also just a foreign key for another table (e.g. Company) with the naive setup of the ID field:

@Id
@ManyToOne()
@JoinColumn(name = "COMPANY_ID")
private Company company;

and then creating a Spring Repository for the entity, I got the error message:

This class [class hu.bmiklos.CompanyAddress] does not define an IdClass

Apparently JPA (or Spring Data, or whatever does the actual magic in the background) thinks that because the class that is used to represent the primary key is not a wrapped primitive, it must be a composite primary key, and thus requires the IdClass annotation for the entity. But declaring an IdClass doesn’t satisfy this requirement, as the underlying field is not a composite key, but the ID of the mapped entity.

The workaround which solved this for me is to declare the ID field twice in the entity, once as the primary key, and once as the foreign key mapped parent entity. (To avoid problems from inconsistent data, JPA requires that both of them can’t be changed in the database though.)

@Id
@Column(name="COMPANY_ID")
private Long companyId;

@ManyToOne()
@JoinColumn(name = "COMPANY_ID", insertable = false, updatable = false)
private Company company;
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

No CEST with JDBC

0 0
Read Time:36 Second

The server time zone value 'CEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

For some reason.

I mean, yes, I’m in the “Central European Summer Time” time zone, but JDBC should not care anyway. Stack Overflow suggests, that I should do what the error message says, and set the serverTimeZone property for the connection. Except that even if I set it, JDBC doesn’t recognise ‘CEST’. Or ‘UTC+2’.

Setting the value to ‘UTC’ works, but I’m not sure yet if it would cause any problems with date/time fields.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

xkcd password generator

0 0
Read Time:1 Minute, 2 Second

xkcd is right that we use passwords which are hard to remember, but easy to crack with computers. Recently my oldest password (the master password for my KeePass file) got compromised, so I suddenly got interested in generating a password that is hard enough, but not easy to remember. I could use some online services that generate an xkcd-inspired password like that, but I don’t really trust passwords generated on other people’s machines. Luckily I have huge collections of words on my machine, so here is this one liner instead:

cat /usr/share/myspell/en_US.dic | ruby -ne 'puts $_[/^[^\s\/]+/]' | ruby -e 'require "securerandom";puts $<.sort_by{SecureRandom.random_number}.take(4)' | tr '\n' ' ' && echo ''

And if 492704 bits aren’t enough for you as entropy, then just be multilingual:

cat /usr/share/myspell/en_US.dic /usr/share/myspell/hu_HU.dic | ruby -ne 'puts $_[/^[^\s\/]+/]' | ruby -e 'require "securerandom";puts $<.sort_by{SecureRandom.random_number}.take(4)' | tr '\n' ' ' && echo ''

(I also wanted to add the German dictionary, but that seems to have some encoding problems.)

EDIT: using secure random instead of a simple shuf

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Looking up my project’s changes

0 0
Read Time:34 Second

Trying to find changes since the release in specific files (.sql and .properties files):

git diff --name-only release/x.x.x.x develop | grep -P "\.(sql|properties)"

Which lists all the files (just the name, not the content) which changed between the two versions provided, then filters it if it either contains .sql or .properties.

Trying to find new rows added to a specific database table:

git diff release/x.x.x.x develop | grep -A 1 -iP "insert into TABLE_NAME"

Which list all the changes between the two versions provided, then filters for the beginning of the SQL insert statement (case insensitively, even though we usually follow our defined code style).

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

MyFaces component not found

0 0
Read Time:3 Minute, 8 Second

So if I have this nice exception on WebSphere 9 with JSF 1.2 (yes, WebSphere 9 uses JSF 2) and MyFaces 1.8 (I guess):

Caused by: javax.faces.FacesException: Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /view/request/other_data.xhtml][Class: javax.faces.component.html.HtmlPanelGroup,Id: main_area]}                                          
     at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:627)                                                                                                                                                                                                                         
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:261)                                                                                                                                                                                                                                 
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:257)                                                                                                                                                                                                                                 
     at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)                                                                                                                                                                                                                       
     at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)                                                                                                                                                                                                               
     at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)                                                                                                                                                                                                                     
     at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)                                                                                                                                                                                                       
     at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)                                                                                                                                                                                                                         
     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:155)                                                                                                                                                                                                                                    
     ... 51 more                                                                                                                                                                                                                                                                                          
 Caused by: javax.faces.FacesException: Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /view/request/other_data.xhtml][Class: javax.faces.component.html.HtmlPanelGroup,Id: main_area][Class: javax.faces.component.html.HtmlForm
     ,Id: main_form][Class: org.apache.myfaces.custom.htmlTag.HtmlTag,Id: contentAreaDiv][Class: javax.faces.component.UINamingContainer,Id: j_id523][Class: org.apache.myfaces.component.html.ext.HtmlMessages,Id: j_id525]}                                                                                 
     at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:627)                                                                                                                                                                                                                         
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:534)                                                                                                                                                                                                        
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChildren(RendererUtils.java:511)                                                                                                                                                                                                     
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:532)                                                                                                                                                                                                        
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChildren(RendererUtils.java:511)                                                                                                                                                                                                     
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:532)                                                                                                                                                                                                        
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChildren(RendererUtils.java:511)                                                                                                                                                                                                     
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:532)                                                                                                                                                                                                        
     at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChildren(RendererUtils.java:511)                                                                                                                                                                                                     
     at org.apache.myfaces.shared_impl.renderkit.html.HtmlGroupRendererBase.encodeEnd(HtmlGroupRendererBase.java:92)                                                                                                                                                                                      
     at org.apache.myfaces.extensions.validator.core.renderkit.ExtValRendererProxy.encodeEnd(ExtValRendererProxy.java:165)                                                                                                                                                                                
     at org.apache.myfaces.extensions.validator.core.renderkit.ExtValRendererWrapper.encodeEnd(ExtValRendererWrapper.java:409)                                                                                                                                                                            
     at org.apache.myfaces.extensions.validator.generic.renderkit.ExtValGenericRendererWrapper.intercept(ExtValGenericRendererWrapper.java:79)                                                                                                                                                            
     at org.apache.myfaces.renderkit.html.HtmlGroupRenderer$$EnhancerByCGLIB$$456d528a.encodeEnd(<generated>)                                                                                                                                                                                             
     at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:624)                                                                                                                                                                                                                         
     ... 59 more                                                                                                                                                                                                                                                                                          
Caused by: java.lang.IllegalArgumentException: Intermediate identifier j_id1161 in search expression j_id1161:birthday identifies a UIComponent that is not a NamingContainer                                                                                                                        
     at javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:460)                                                                                                                                                                                                                     
     at javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:463)                                                                                                                                                                                                                     
     at org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer.findInputLabel(HtmlMessageRenderer.java:166)                                                                                                                                                                                            
     at org.apache.myfaces.renderkit.html.ext.HtmlMessagesRenderer.getSummary(HtmlMessagesRenderer.java:80)                                                                                                                                                                                               
     at org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlMessageRendererBase.renderSingleFacesMessage(HtmlMessageRendererBase.java:133)                                                                                                                                                              
     at org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlMessagesRendererBase.renderList(HtmlMessagesRendererBase.java:99)                                                                                                                                                                           
     at org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlMessagesRendererBase.renderMessages(HtmlMessagesRendererBase.java:80)                                                                                                                                                                       
     at org.apache.myfaces.renderkit.html.ext.HtmlMessagesRenderer.encodeEnd(HtmlMessagesRenderer.java:52)                                                                                                                                                                                                
     at org.apache.myfaces.extensions.validator.core.renderkit.ExtValRendererProxy.encodeEnd(ExtValRendererProxy.java:165)                                                                                                                                                                                
     at org.apache.myfaces.extensions.validator.core.renderkit.ExtValRendererWrapper.encodeEnd(ExtValRendererWrapper.java:409)                                                                                                                                                                            
     at org.apache.myfaces.extensions.validator.generic.renderkit.ExtValGenericRendererWrapper.intercept(ExtValGenericRendererWrapper.java:79)                                                                                                                                                            
     at org.apache.myfaces.renderkit.html.ext.HtmlMessagesRenderer$$EnhancerByCGLIB$$a0c2e090.encodeEnd(<generated>)                                                                                                                                                                                      
     at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:624)                                                                                                                                                                                                                         
     ... 73 more

looking for a component that is referenced even though it’s not on the same page, it’s because f:subview requires an id attribute, and even though it was working without it well for 10 years (note that it gets an automatically generated ID), looking it up now runs into problems for some reason.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

AngularJS formatter/parser is (not) type sensitive

0 0
Read Time:1 Minute, 1 Second

I have a small AngularJS (1.x) directive so my input field does not show the value the is in the model, but formats it before (and parses the user input from the input field’s format):

angular.module('appModule')
       .directive('fooformat', function() {

    function parse(formattedValue) {
        return formattedValue.replace('foo', '');
    }

    function format(value) {
        return value + "foo";
    }

    return {
        restrict: 'A',
        require: 'ngModel',
        link: function(scope, element, attr, ngModel) {
            ngModel.$parsers.push(parse);
            ngModel.$formatters.push(format);
        }
    };
});

This does not seem to work, the fields always get empty, even though that debugging shows that the conversions are done as expected. E.g. for the string "1" the return value would become "1foo".

What seems to work is, if the changes are numerical. E.g.:

function parse(formattedValue) {
    return formattedValue - 1;
}

function format(value) {
    return value + 1;
}

This would format "1" as 2, and suddenly it would work.

Well, it’s not AngularJS formatter/parser which is sensitive to the types, but the HTML5 input field where I use it:

<input fooformat type="number ng-model="" />

needs to be changed to

<input fooformat type="text" ng-model="foo" />

Happy

Happy

0 %


Sad

Sad

0 %


Excited

Excited

0 %


Sleepy

Sleepy

0 %


Angry

Angry

0 %


Surprise

Surprise

0 %

Bitbucket pipeline dependency

0 0
Read Time:27 Second

My Bitbucket pipeline failed with the error message:

+ bundle exec hanami db prepare
sh: 1: sqlite3: not found
/usr/local/bundle/gems/hanami-model-1.2.0/lib/hanami/model/migrator/adapter.rb:214:in `block in execute'
/usr/local/bundle/gems/hanami-model-1.2.0/lib/hanami/model/migrator/adapter.rb:216:in `block in execute'
...

Apparently the Ruby Docker image is based on Debian, so I can just add

...
script:
- apt-get update && apt-get install sqlite3
... 

to my bitbucket-pipelines.yml file.


Happy

Happy

0 %


Sad

Sad

0 %


Excited

Excited

0 %


Sleepy

Sleepy

0 %


Angry

Angry

0 %


Surprise

Surprise

0 %

A program with an incorrect format

0 0
Read Time:52 Second

Server Error in '/Web.Api' Application.
Could not load file or assembly 'Oracle.ManagedDataAccessDTC' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly ‘Oracle.ManagedDataAccessDTC’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

In my case this isn’t really an issue with the Oracle dependencies. The key here is the An attempt was made to load a program with an incorrect format part. The problem occurs on my local Windows 10 (x86_64) machine with IIS 10. And yes, the project builds for 32 bit, not 64 bit. Setting “Enable 32-bit applications” in the “Advanced settings…” of the web site (“Default Web Site” in my case), in the “Application Pools” solves the problem.


Happy

Happy

0 %


Sad

Sad

0 %


Excited

Excited

0 %


Sleepy

Sleepy

0 %


Angry

Angry

0 %


Surprise

Surprise

0 %

Cherry-picking changes from a file to a different file

0 0
Read Time:23 Second

I have a file.
I have another file on a different path on a different branch with mostly the same content.
I have changes in my first file.
I want to move these changes to my second file.
The files have the same name, only the path differs.
(I also need to ignore changes in whitespace, because consistency.)

Solution:

git show SHA_HASH --relative=original/path/ -- original//path/file.name | git apply --directory=new/path/ --ignore-space-change -


Happy

Happy

0 %


Sad

Sad

0 %


Excited

Excited

0 %


Sleepy

Sleepy

0 %


Angry

Angry

0 %


Surprise

Surprise

0 %