OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Check SubResource Integrity

Open hishamco opened this issue 4 years ago • 24 comments

Fixes #9941

hishamco avatar Jul 21 '21 21:07 hishamco

@agriffard @deanmarcussen what I notice that many files in my local don't have the same SRI, for example ~/OrchardCore.Resources/Scripts/js.cookie.js so when I download that file from CDN I got the same exact SRI

Could you please let me know if there's something I can do? That's why the Test fails in both my end and GitHub

hishamco avatar Jul 21 '21 22:07 hishamco

The following are the file that have the exact same SRI:

  • ~/OrchardCore.Resources/Scripts/jquery-ui-i18n.min.js
  • ~/OrchardCore.Resources/Scripts/vue-multiselect.min.js
  • ~/OrchardCore.Resources/Scripts/vue-multiselect.min.js

hishamco avatar Jul 21 '21 22:07 hishamco

I would suggest picking a specific file that doesn't match, and using the online https://www.srihash.org/ that I suspect @agriffard is using to test why one is not working, perhaps they are using different hashing methods.

deanmarcussen avatar Aug 29 '21 07:08 deanmarcussen

@agriffard are using SHA384 when you generate the hash in SRI? Or are you using another one?

hishamco avatar Aug 29 '21 13:08 hishamco

@agriffard are using SHA384 when you generate the hash in SRI? Or are you using another one?

Yes, I do. I always use https://www.srihash.org/ and the default encryption is SHA-384.

agriffard avatar Aug 29 '21 13:08 agriffard

@agriffard how can I ensure that all the resources in my side are up to date, so I can validate the SRI for them

hishamco avatar Aug 29 '21 14:08 hishamco

FYI I tried npm run but I'm getting an error

hishamco avatar Aug 29 '21 16:08 hishamco

@agriffard could you let me know what should I do here to make a successful restore for npm packages. I need to finalize this PR

hishamco avatar Sep 26 '21 11:09 hishamco

@agriffard could you let me know what should I do here to make a successful restore for npm packages. I need to finalize this PR

npm install

agriffard avatar Sep 27 '21 21:09 agriffard

NPM

hishamco avatar Sep 29 '21 09:09 hishamco

@hishamco Update your node.js and/or npm to latest LTS version.

Skrypt avatar Oct 05 '21 14:10 Skrypt

I already updated Node JS, I need to check again, coz it success with UI Testing project .. I will have a try

hishamco avatar Oct 05 '21 14:10 hishamco

Gulp

hishamco avatar Oct 05 '21 15:10 hishamco

Once you installed the new node.js and npm try and do a cleanup of the node_modules folder. Then redo npm install.

Skrypt avatar Oct 05 '21 16:10 Skrypt

@Skrypt is package-lock.json play an important role, what I notice is when I download the exact file from the CDN the SRI validated successfully. This make me think that some of my local assest are not updated

I tried npm run rebuild with no luck :(

hishamco avatar Oct 16 '21 21:10 hishamco

Sometimes I do a git clean -xdf to clean also the package-lock.json files and retrieve those from the repository. It can be a node_modules cache on your computer too. There are so many things that can go wrong in node.js dependency hell...

Skrypt avatar Oct 17 '21 21:10 Skrypt

@agriffard this PR is ready, I know the build will fail because I discover there are many invalid SRI, so I will create another PR to fix them. Once you merge the other PR we could rebase on main then the build will pass

hishamco avatar May 30 '23 13:05 hishamco

I cancelled the workflows, the build was running without progress for 1h40.

agriffard avatar May 30 '23 15:05 agriffard

That's why I didn't the build failed, I might need to check the logs

hishamco avatar May 30 '23 15:05 hishamco

Seems the resources take time to validate the SRI, which is weird!!

hishamco avatar May 30 '23 16:05 hishamco

Is this something you'd like to revisit any time soon @hishamco? Would be quite useful.

Piedone avatar Jan 16 '24 01:01 Piedone

Sure, there are many PRs on my list :)

hishamco avatar Jan 16 '24 08:01 hishamco

Seems the old issue in the testing has been resolved https://github.com/OrchardCMS/OrchardCore/pull/9947#issuecomment-1568750419

@Piedone I think we're ready to merge this now

hishamco avatar Jan 19 '24 18:01 hishamco

Let me know if you'd like a review here.

Piedone avatar Feb 04 '24 21:02 Piedone

@Piedone time to merge :)

hishamco avatar Feb 26 '24 07:02 hishamco

Please request review when you're done, because I just noticed this randomly.

Piedone avatar Mar 01 '24 19:03 Piedone

Use the new static instances instead of creating new ones: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha384.hashdata?view=net-8.0

sebastienros avatar Mar 05 '24 20:03 sebastienros

I am right that these will run also locally? If so would you want to create an XUnit attribute to add on the methods which would skip the test if the "CI" environment variable is defined?

public class CiOnlyFactAttribute : FactAttribute
{
    public override string Skip
    {
        get
        {
            // "CI" is defined by GitHub actions
            // "BUILD_BUILDID" is defined by Azure DevOps

            if (Environment.GetEnvironmentVariable("BUILD_BUILDID") != null || 
                Environment.GetEnvironmentVariable("CI") != null)
            {
                return $"nameof(CiOnlyFactAttribute) tests are not run locally. To run them locally create a \"CI\" environment variable.";
            }

            return null!;
        }
    }
}

sebastienros avatar Mar 06 '24 01:03 sebastienros

We could do that, but I'm not sure do we still need Azure DevOps, while we're using GitHub actions?

hishamco avatar Mar 06 '24 07:03 hishamco

Why would we skip these in CI?

Piedone avatar Mar 06 '24 18:03 Piedone