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

Publish a new package, loguru-hardened, with security focussed defaults #1136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bneijt
Copy link

@bneijt bneijt commented May 4, 2024

Introduce a separate script that will override a few files to harden loguru defaults and build a loguru-hardened package, then revert the changes using git.

hardened/_defaults.py Outdated Show resolved Hide resolved
build_hardened.py Outdated Show resolved Hide resolved
@Delgan
Copy link
Owner

Delgan commented May 9, 2024

I don't know why 3.13 build fails, maybe try rebasing (a few libraries were updated since then)?

@trim21
Copy link
Contributor

trim21 commented May 10, 2024

if it's serialized be default, should we also remove level time from default format?

@bneijt bneijt force-pushed the hardened branch 2 times, most recently from c5f9775 to 92cd74c Compare May 11, 2024 19:40
@bneijt
Copy link
Author

bneijt commented May 11, 2024

if it's serialized be default, should we also remove level time from default format?

I don't follow, could you give a code example of what you mean or explain further?

@trim21
Copy link
Contributor

trim21 commented May 12, 2024

if it's serialized be default, should we also remove level time from default format?

I don't follow, could you give a code example of what you mean or explain further?

from

LOGURU_FORMAT = env(
    "LOGURU_FORMAT",
    str,
    "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | "
    "<level>{level: <8}</level> | "
    "<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
)

to

LOGURU_FORMAT = env("LOGURU_FORMAT", str, "{message}")

@@ -40,6 +40,7 @@ Installation

pip install loguru

Or if you need more secure defaults, install ``loguru-hardened``.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also mentioned loguru-hardened in the README, but I could not find a release action configured, so I'm not sure how to make sure hardened is also released when a new release is created.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, since there is no Github Action, I need to do it manually for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could open up another pr with release workflows if you would like that. I don't know what currently goes into the manual release actions, but it might be a nice setup to simplify maintenance.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bneijt Thanks for the proposal. If you're familiar with release automation via Github Actions, your help is most welcome. I'd like to replace manual release management.

Also sorry for not having yet merged this PR, but it seems it will be incompatible with #1140. I need to check how to create loguru-hardened without setup.py.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use a Python script change project.name in new pyproject.toml file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can help write a ci file

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trim21 Yes, I suppose this should be straightforward. Unfortunately, this PR will need to be updated, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider merge 1140 first maybe....

@bneijt bneijt changed the title Use separate script to build hardened variant Publish a new package, loguru-hardened, with security focussed defaults May 12, 2024
@Delgan
Copy link
Owner

Delgan commented May 16, 2024

I finally fixed CI for Python 3.5 and 3.13, can you try rebasing the PR please?

@trim21
Copy link
Contributor

trim21 commented Jun 1, 2024

I have a question about this, what if a package I'm using require loguru, and my application require this package, and use loguru-hardened? it will conflict

my app
├── package
│   └── loguru
└── loguru-hardened

a possible solution here would be, instead of new package, add a extra,this extra require a new package loguru-hardened, but it do nothing.

Then in loguru, we just check if package loguru-hardened exists, and if it exists, use hardened default.

so instead of install loguru-hardened and cause conflect, users can just install loguru[hardened], and works fine with package require loguru

try:
    import loguru._hardened
    HARDENED_ENABLED = True
except ImportError:
    HARDENED_ENABLED = False

@bneijt
Copy link
Author

bneijt commented Jun 3, 2024

I have a question about this, what if a package I'm using require loguru, and my application require this package, and use loguru-hardened? it will conflict

Yes, there will be a conflict which needs to be solved by uninstalling or ignoring the loguru package in environments that require you to use a hardened version instead.

The proposed workaround of using an extra won’t work because the reason for having this package is to facilitate environments where static code analysis like sonarqube flag loguru for being difficult to use in a secure way.

Which means that we can’t have loguru installed.

Next week I will find some time to create a hood example of how to use loguru hardened in those situations and explain how to deal with oackages that require loguru.

@trim21
Copy link
Contributor

trim21 commented Jun 3, 2024

Yes, there will be a conflict which needs to be solved by uninstalling or ignoring the loguru package in environments that require you to use a hardened version instead.

I don't think this is a solution...

in some case you don't have control which package will be installed first, loguru or loguru-hardened, which mean it's possible loguru override loguru-hardened, not what we are expecting, loguru-hardened over loguru.

The proposed workaround of using an extra won’t work because the reason for having this package is to facilitate environments where static code analysis like sonarqube flag loguru for being difficult to use in a secure way.

Which means that we can’t have loguru installed.

That's false positive problem of static code analysi themselve, right?
It doesn't make sence if you have env var LOGURU_SERIALIZE=True, you won't (can't) have multiple line log message in json

@bneijt
Copy link
Author

bneijt commented Jun 3, 2024

That's false positive problem of static code analysi themselve, right? It doesn't make sence if you have env var LOGURU_SERIALIZE=True, you won't (can't) have multiple line log message in json

Yes and no.. it is not a false positive that “the default don’t protect against line injection properly”, but you are right that that is a bad mark in the first place because that same reasoning should flag Python itself (logging has the same issue) ;)

@trim21
Copy link
Contributor

trim21 commented Jun 3, 2024

Yes and no.. it is not a false positive that “the default don’t protect against line injection properly”, but you are right that that is a bad mark in the first place because that same reasoning should flag Python itself (logging has the same issue) ;)

So with extra, the default has been changed, right?

or no matter how loguru changed, it will just flag loguru anyway?

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.

None yet

3 participants