Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome extensions support #534

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

alessandro-Doyensec
Copy link
Contributor

Extraction of chrome extensions support for scalibr

Resources:

Notes:

I used runtime.GOOS to detect the operating system where scalibr is running. This approach works when the scan target is the host machine, but it doesn't function as expected when scanning a remote image.

Do scalibr plugins have a way to detect if the scan target is running a different operating system than the host?

@alessandro-Doyensec
Copy link
Contributor Author

Hey @erikvarga I still have a test failing in windows

=== RUN   TestExtractor_Extract
=== RUN   TestExtractor_Extract/no_locale_specified
=== RUN   TestExtractor_Extract/default_locale_specified_but_no_message_file_provided
=== RUN   TestExtractor_Extract/locale_specified
    extensions_test.go:149: chrome/extensions.Extract("testdata/ghbmnnjooekpmoecnnnilnnbdlolhkhi/1.89.1/manifest.json") error diff (-want +got):
          any(
        + 	e`could not extract locale info from testdata/ghbmnnjooekpmoecnnnilnnbdlolhkhi/1.89.1/manifest.json: open testdata\ghbmnnjooekpmoecnnnilnnbdlolhkhi\1.89.1\_locales\en_US\message.json: invalid argument`,
          )
--- FAIL: TestExtractor_Extract (0.02s)
    --- PASS: TestExtractor_Extract/no_locale_specified (0.01s)
    --- PASS: TestExtractor_Extract/default_locale_specified_but_no_message_file_provided (0.00s)
    --- FAIL: TestExtractor_Extract/locale_specified (0.00s)
FAIL
FAIL	github.com/google/osv-scalibr/extractor/filesystem/misc/chrome/extensions	0.561s
FAIL

this is the patch that fixes it

diff --git a/extractor/filesystem/misc/chrome/extensions/extensions.go b/extractor/filesystem/misc/chrome/extensions/extensions.go
index a910b29..7aa0ac7 100644
--- a/extractor/filesystem/misc/chrome/extensions/extensions.go
+++ b/extractor/filesystem/misc/chrome/extensions/extensions.go
@@ -180,6 +180,7 @@ func extractExtensionsIDFromPath(input *filesystem.ScanInput) (string, error) {
 // following manifest.json v3 specification
 func extractLocaleInfo(m *manifest, input *filesystem.ScanInput) error {
 	messagePath := filepath.Join(filepath.Dir(input.Path), "_locales", m.DefaultLocale, "message.json")
+	messagePath = filepath.ToSlash(messagePath)
 
 	f, err := input.FS.Open(messagePath)
 	if err != nil {

which to me seems kinda odd, do you have any idea why using filepath.ToSlash is required before calling input.FS.Open?

@erikvarga
Copy link
Collaborator

I think the issue is that the fs.FS interface expects all paths to be normalized to use forward slashes. On Windows iflepath.Join would add backwards slashes which is not what fs.FS expects. So you can either concatenate the paths with "/" directly or call filepth.ToSlash as you do there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants