Skip to content

Add custom character limit to pastes#196

Merged
mtlynch merged 6 commits into
mtlynch:masterfrom
csfore:custom-char-limit
Dec 4, 2023
Merged

Add custom character limit to pastes#196
mtlynch merged 6 commits into
mtlynch:masterfrom
csfore:custom-char-limit

Conversation

@csfore

@csfore csfore commented Dec 1, 2023

Copy link
Copy Markdown
Contributor

Background

Recently I've been looking at alternatives to the service 0x0.st for pasting log files to. Logpaste seems like the perfect replacement, but it has limits on file size. Adding the ability for administrators to add custom file sizes would allow admins to make the file size the equivalent of 0x0's (512 MiB) or even larger. It would also allow them to set smaller limits as well if resources are limited or if the content being pasted doesn't warrant large sizes.

Changes

  • The default limit is now 2 * 1024 * 1024, or 2 MiB instead of 2 * 1000 * 1000, 2 MB
  • Add cli flag -maxsize int to allow admins to set an arbitrary limit on paste file sizes if they would like to
    • The argument is passed in by # of MiB (so for a 512MiB limit, -maxsize 512, or for the default 2MiB, -maxsize 2)
  • Add field maxCharLimit to the defaultServer struct for storing the given size
  • Add fields to handlers/paste_test.go to use the new struct field in order for tests to pass
  • Replace instances of MaxPasteCharacters with s.maxCharLimit

@csfore csfore force-pushed the custom-char-limit branch 2 times, most recently from 66dd581 to 3f900d5 Compare December 1, 2023 17:31

@mtlynch mtlynch left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Cool, thanks for adding this! I just have a small note.

Comment thread cmd/logpaste/main.go Outdated
true, "whether to display usage information on homepage")
perMinuteLimit := flag.Int("perminutelimit",
0, "number of pastes to allow per IP per minute (set to 0 to disable rate limiting)")
maxCharLimit := flag.Int64("maxsize", 2, "max file size as MiB")

@mtlynch mtlynch Dec 2, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we reword this to "max files size in MiB"?

And can we change the var name to maxPasteMiB? It's a little confusing to call it maxCharLimit at the point that it represents the MiB limit rather than the character limit.

The conversion from MiB to characters should be the same time we rename it like:

const charactersPerMiB = 1024 * 1024
maxCharLimit := *maxPasteMiB * charactersPerMiB

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! For the other files, paste.go and server.go, is maxCharLimit fine in there or should I rename those too?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yeah, I think main.go is the only file that should deal in terms of max MiB. main.go should convert it to characters, and then the rest of the code deals in terms of max characters.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Oh, can we also document the new flag in the README?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Definitely, I'll be a little busy this weekend but hopefully I'll get those fixed by tomorrow evening!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just pushed the changes!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, can you document the new flag in the README as well?

Also, can you avoid force-pushing? It makes it hard to review version-to-version changes. The last change you made is probably pretty small, but the only way to see it is mixed in with the single commit of all the changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll go ahead and add to the README. Sorry about force pushing, I'm just used to squashing by default.

Some pastebins might wish to have an arbitrary character limit, so this
aims to add that with a CLI flag.
@csfore csfore force-pushed the custom-char-limit branch from 3f900d5 to 11548df Compare December 3, 2023 03:46

@mtlynch mtlynch left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM, thanks!

@mtlynch mtlynch enabled auto-merge (squash) December 4, 2023 01:27
@csfore

csfore commented Dec 4, 2023

Copy link
Copy Markdown
Contributor Author

No problem! Sorry about the errors, it's been a long weekend haha

@mtlynch mtlynch merged commit a883a44 into mtlynch:master Dec 4, 2023
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.

2 participants