TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How to secure website for public launch

94 点作者 smarri大约 1 年前
Id like to launch a website project online. It has some functionality e.g. user can input search parameters to find specific locations using Goole maps API, and search based on device location. I'm concerned about my program not being robust enough from a security point of view, e.g. where user input occurs, I'm not confident I can manage malicious actors. How do you launch websites that use a front and back end, securely? I'm confident in launching static websites, reasonably experienced in python, PHP, (but only for localhost personal project work), this is really me taking the big leap from localhost projects to live. Are there third party services that give extra security, or is it a case of learning this side of software from first principles? Thanks in advance.

16 条评论

gerardnico大约 1 年前
The biggest security hole is user input.<p>Just escape every input: For sql, to avoid sql injection: <a href="https:&#x2F;&#x2F;datacadamia.com&#x2F;data&#x2F;type&#x2F;relation&#x2F;sql&#x2F;parameter" rel="nofollow">https:&#x2F;&#x2F;datacadamia.com&#x2F;data&#x2F;type&#x2F;relation&#x2F;sql&#x2F;parameter</a> For html, if somebody try to inject html: <a href="https:&#x2F;&#x2F;datacadamia.com&#x2F;web&#x2F;html&#x2F;entity" rel="nofollow">https:&#x2F;&#x2F;datacadamia.com&#x2F;web&#x2F;html&#x2F;entity</a><p>You got 99% of security holes patched.<p>All the best
评论 #39876284 未加载
评论 #39878959 未加载
评论 #39877068 未加载
solardev大约 1 年前
If you&#x27;re not sure, put everything behind Cloudflare and don&#x27;t expose your origin at all. Proxy the API requests through workers or at least shield them behind page rules.<p>Implement some basic rate limiting by IP so you don&#x27;t get your Google Maps API DoSed. Block China and Russia altogether unless you expect customers from there (sadly, many bots &amp; drive-by scans originate there). Sanitize your inputs, especially if you have any that will reach one of your own endpoints like for a database lookup (and look into SQL injection prevention in general). Use prepared statements in PHP if you use that for DB access. Not sure about Python.<p>You can read OWASP guidelines for other best practices (<a href="https:&#x2F;&#x2F;owasp.org&#x2F;www-project-top-ten&#x2F;" rel="nofollow">https:&#x2F;&#x2F;owasp.org&#x2F;www-project-top-ten&#x2F;</a>) or ask ChatGPT to summarize. But realistically, Cloudflare takes care of so much that it seems a bit foolhardy to try to DIY it these days...<p>If it were me doing this, I wouldn&#x27;t self-host anything at all, and just use managed services all the way down, including the DBs. A lot less maintenance that way, especially for solo devs. Lets you focus on the business logic instead of trying to reinvent your own secure little nano cloud. It takes serious manpower to stay on top of the latest vulnerabilities and zero-days, and IMO it&#x27;s not worth spending your limited time on that when the big clouds can do it much more cheaply and much more thoroughly... it&#x27;s a full-time job in and of itself, and you still probably wouldn&#x27;t keep up with all the latest attacks =&#x2F;<p>Of course you end up learning less this way because other professionals do all the hard work for you. But unless you want to become a backend&#x2F;security professional yourself and REALLY dive deep into this stuff, I don&#x27;t think just having basic security skills is going to do you much good anyway, since it takes all of 30 seconds to spin up a pre-hardened cloud host these days, usually for free, and they will have much more exhaustive coverage. Just my 2c.
评论 #39875993 未加载
评论 #39875902 未加载
mycentstoo大约 1 年前
A few infrastructure things:<p>- Serve traffic behind a load balancer that has a WAF<p>- Network segregation for database (separate subnets)<p>- Make sure you serve https and have a cert that’s valid. Redirect to https if http<p>- Restrict ports on LB<p>At some point later:<p>- Endpoint monitoring and threat detection<p>- VPC flow logging<p>- Execute backend as non root<p>- Dependency &#x2F; artifact scanning<p>- Cloud SIEM to monitor common actions taken<p>- Make sure no hard coded creds. Ie, use role-base auth with cloud providers<p>- Reproducible infrastructure builds with infra as code<p>- Email domain protection<p>- Grab misspellings of domain names to prevent squatting
评论 #39876406 未加载
评论 #39876299 未加载
评论 #39876422 未加载
kqr大约 1 年前
The fact that you&#x27;re concerned in the first place is a great indicator that you have already avoided the gravest and most common mistake!
mrkeen大约 1 年前
* keep your software &amp; dependencies patched<p>* Disable SSH access for &#x27;root&#x27; username.<p>* If you&#x27;re using JWTs anywhere, don&#x27;t mistake them for encryption - they are not.<p>* Check you&#x27;re only serving over https.<p>* Don&#x27;t trust your frontend. Any security check built into the frontend is near-useless, as the user can reprogram it however they like.<p>* Strings is how you let the baddies in, especially if you manipulate and concatenate them. Read about SQL injection to find out more.
评论 #39875926 未加载
Semionilo大约 1 年前
Use some software input fuzzer against it like SQL fuzzer etc.<p>Never trust your frontend data ever!<p>Always assume the attacker can talk to your API.<p>Don&#x27;t do auth or login yourself. Use known libs, workflows asks.<p>Have unit tests to verify your endpoints need auth (valid user not just a anonymous user)
apwheele大约 1 年前
I have a similar background, and I just use a $5 a month Hostinger plan that manages the PHP server and I am quite happy with it. So it is just keeping my server side secrets in PHP in a way that makes sense.<p>Now, this does not allow me to say do python web-apps (that are not WASM). Hostinger has VPS for quite cheap I would consider if I needed that (if AWS lambda does not make sense, I did a python google cloud app engine for a month, <a href="https:&#x2F;&#x2F;crimede-coder.com&#x2F;graphs&#x2F;Dallas_Dashboard" rel="nofollow">https:&#x2F;&#x2F;crimede-coder.com&#x2F;graphs&#x2F;Dallas_Dashboard</a>, and that was pricey, like $80 a month, whereas the WASM app is no additional cost). And I am sure there are other vendors that are similar (I am just happy with Hostinger).<p>So in terms of DDOS protection this is not so great, but that would not be a big deal to me. So site goes down, but I do not rack up a bill or anything.<p>For a google maps application, I not un-commonly see people put API keys in javascript client side (not good!) I mean it depends on what exactly you are doing, but if it is a public service that users do not sign into, just rate limiting the number of API queries in some PHP + database logic server side should be not too much work and reasonable to not rack up a surprise bill (I forget if google allows you to limit the API keys directly or if they will just rack up bills).
precommunicator大约 1 年前
Read OWASP ASVS. That&#x27;s a really good start, if you did everything yourself, you will find many issues even without further analysis of code.
forgotmyinfo大约 1 年前
Get someone else to manage it for you while you learn. Security is an emergent property of every part of the stack, not a separate thing you can do after the fact. Get a handle on the fundamentals, too: fundamentals of TCP&#x2F;IP, HTTP&#x2F;S, etc.
chrisjshull大约 1 年前
If you are using the Google Maps JavaScript API: <a href="https:&#x2F;&#x2F;developers.google.com&#x2F;maps&#x2F;api-security-best-practices" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;maps&#x2F;api-security-best-practic...</a>
rgbimbochamp大约 1 年前
This might help: <a href="https:&#x2F;&#x2F;smunshi.net&#x2F;secure-infrastructure-design-interview-cheat-sheet.html" rel="nofollow">https:&#x2F;&#x2F;smunshi.net&#x2F;secure-infrastructure-design-interview-c...</a>
g_p大约 1 年前
You&#x27;ve got some other good advice in other replies on specific steps to take around infrastructure and software&#x2F; dependencies.<p>To turn the question around a bit - you&#x27;ve identified the possible routes of compromise&#x2F;exploitation (i.e. untrusted user input). The first step to me is a threat model. Work out the &quot;so what&quot; of why someone would try to attack you. What would be their end-goal?<p>To give you a few first steps, you&#x27;ve mentioned using a Google Maps API, and searching based on device location. Presumably your use of the Maps API is paid, and therefore a potential motivation for an attacker is financial, coming from your use of that API. Therefore treat that (i.e. the ability to make requests using your Google Maps API key) as a &quot;target&quot; in your architecture.<p>From there, you can do things to be a less attractive target (rate limiting, limiting results shown, if you are charged per-result). You could also review your code logic to ensure that only the right kind of request can be made (i.e. that someone modifying the client-side can&#x27;t trick your server into accidentally making entirely arbitrary paid maps API requests on their behalf).<p>At this point, you&#x27;d also want to figure out your threat model between client-side and server-side, and what is exposed where. Assuming your server-side makes the API requests to Google Maps (and if not, then you&#x27;re presumably exposing your API creds to clients, which is a &quot;stop right here, don&#x27;t proceed&quot; moment!), what is allowed to flow from client to server? Can a rogue client get your server to make an arbitrary query? Would that let them use you as a free Google Maps API broker?<p>Understanding the trust architecture between front and back-end is (for me at least) key, as that&#x27;s the primary exposed attack surface to an end user. Open up developer tools (F12), and look around requests as you use the app. Is there anything here that you wouldn&#x27;t want users to see? As attackers will definitely see that, and it will be the first place they go to look at what you are doing!<p>Other ways to mitigate these risks could be (if you have sufficiently constrained input sets) to implement caching to avoid the ability to rack up queries against the underlying maps API. Given you are using arbitrary user locations, that&#x27;s a bit harder. If users have a session or other short to medium term identifier, you could do some smart rate limiting to detect rampant scanning of large areas by making API requests that spoof the device location to be loads of different locations.<p>If you follow this process, and work out what&#x27;s worth attacking (your infrastructure will be one of them - even just to compromise the site, post spam, etc, as will things like any database you run), then you can begin to understand those risks, and work out where there are attack vectors, and mitigate them methodically. The OWASP top 10 guidelines are a good starting point - often the biggest issues are design mistakes, omissions of basic omissions, or flawed attempts to implement basic measures. If you have authenticated API endpoints, for example, is the authentication logic correct, and meaningful? Does it actually do what you intend, and is what you intend sufficient for the level of security you want to have?
traviswingo大约 1 年前
This sounds an awful lot like analysis paralysis to me. My recommendation: just launch. You probably won’t run into any of the problems you’re worried about and, if you do, you can just patch them up.<p>As you launch more and spend more time dealing with users the default things to do will become second nature, and you’ll find yourself using the built in tools from AWS, DigitalOcean, CloudFlare, etc. rather than rolling them yourself.<p>But seriously, just launch. There’s a really good chance you won’t have any problems.
评论 #39876502 未加载
评论 #39876666 未加载
评论 #39877733 未加载
smarri大约 1 年前
Thank you all for the advice and suggestions.
phonon大约 1 年前
Use Django.
joshxyz大约 1 年前
you can always rollback.
评论 #39875758 未加载